当启动活动在后台时,第二个活动将不会打开

时间:2013-03-23 18:58:15

标签: android multithreading android-activity

我有两项相关活动:MainShowResult。第二个是从Main中的一个线程启动的。这很有效,但只要Main处于后台,活动就无法打开。 Logcat没有显示任何异常。

清单:

<activity
        android:name="com.....ShowResultActivity"
        android:launchMode="singleTop"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:screenOrientation="landscape"
        android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" >
    </activity>

    <activity
        android:name="com......MainActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:screenOrientation="landscape"
        android:theme="@android:style/Theme.Holo.Wallpaper.NoTitleBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.HOME" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Thread-class中的处理程序/从Thread执行:

iOpen = new Intent(context, ShowResultActivity.class); // is written in the constructor
Bundle b = new Bundle(); // global

b.putInt("type", 1);
b.putString("url", value);
iOpen.putExtras(b);
context.startActivity(iOpen);

ShowResult:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    onNewIntent(getIntent());
}

@Override 
public void  onNewIntent(Intent i) {
    Bundle b = i.getExtras();
    int value = b.getInt("type");
    String url = b.getString("url");

    Log.e("opened :)", value+" "+url);

    if(value == 0) {
        showPictureAsync(url);
    } else if (value == 1) {
        showVideoAsync(url);
    }

}

1 个答案:

答案 0 :(得分:0)

将此添加到您的代码中

iOpen.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(iOpen);