从主屏幕快捷方式启动第二个活动时,将弹出主要活动

时间:2012-03-12 18:53:27

标签: java android shortcut homescreen

我的应用程序有两个主要活动。一个带GUI的活动(启动)。第二个主要活动(launch2),没有GUI来执行选定的网络任务。可以从主屏幕快捷方式启动第二个活动。到目前为止一切顺利,当主要活动没有在后台运行时,它工作得很好。 如果在主活动运行时按下主屏幕按钮,则活动暂停。当我按下快捷键时,第二个活动就会启动,但主要活动也会恢复。

清单:

    <activity android:name=".launch"
        android:configChanges="orientation|keyboardHidden"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.CREATE_SHORTCUT"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>   
    </activity>
    <activity  android:name=".Launch2"
              android:configChanges="orientation|keyboardHidden"
              android:label="@string/app_name"
              android:theme="@android:style/Theme.NoDisplay">
              <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
              </intent-filter>
    </activity>    

快捷方式是在lauch(主要活动)中通过以下方式创建:

void saveShortcut(int nr, String text){
    Intent shortcutIntent = new Intent(this,Launch2.class);
    shortcutIntent.putExtra("shortcut", nr+1);
    Intent intent = new Intent(this,launch.class);
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, text);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
    Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));
    intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    setResult(RESULT_OK, intent);   
    finish();
}

0 个答案:

没有答案
相关问题