Note that there are some explanatory texts on larger screens.

plurals
  1. POBug: onNewIntent not called for singleTop activity with Intent.FLAG_ACTIVITY_NEW_TASK
    primarykey
    data
    text
    <p>There appears to be a bug in <code>startActivity</code>.</p> <p>By setting activities to be <code>singleTop</code> with different <code>taskAffinity</code> in AndroidManifest.xml and using the <code>Intent.FLAG_ACTIVITY_NEW_TASK</code> when calling <code>startActivity</code>, two activities can be created in two tasks (one activity per task).</p> <p>Calling <code>startActivity</code> again will return to the first activity/task and <code>onNewIntent</code> is called. However, calling <code>startActivity</code> a forth time will return to the second activity/task, but <code>onNewIntent</code> is not called.</p> <p>The only difference between the two tasks is their <code>taskAffinity</code>. Somehow, asymmetrical behaviour is observed.</p> <p>However, if the <code>Intent.FLAG_ACTIVITY_SINGLE_TOP</code> is also used, then <code>onNewIntent</code> is called as expected.</p> <p>It would appear that <code>singleTop</code> in AndroidManifest.xml is not the same as <code>Intent.FLAG_ACTIVITY_SINGLE_TOP</code> in the <code>Intent</code>.</p> <pre> public class ActivityA extends Activity implements OnClickListener { private String tag; @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); tag = getClass().getName(); Log.v(tag, "onCreate()"); setContentView(R.layout.main); Button button = (Button)findViewById(R.id.button); button.setText(tag.endsWith("ActivityA") ? "Activity B" : "Activity A"); button.setOnClickListener(this); } @Override public void onClick(View v) { Intent intent; int flags = Intent.FLAG_ACTIVITY_NEW_TASK // | Intent.FLAG_ACTIVITY_SINGLE_TOP ; Log.v(tag, "onClick()"); intent = new Intent(this, tag.endsWith("ActivityA") ? ActivityB.class : ActivityA.class); intent.setFlags(flags); startActivity(intent); } @Override protected void onNewIntent(Intent intent) { Log.v(tag, "onNewIntent()"); } } </pre> <pre> public class ActivityB extends ActivityA { } </pre> <pre> &lt;?xml version="1.0" encoding="utf-8"?> &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.test" android:versionCode="1" android:versionName="1.0"> &lt;application android:icon="@drawable/icon" android:label="@string/app_name"> &lt;activity android:name=".ActivityA" android:launchMode="singleTop" android:label="Activity A"> &lt;intent-filter> &lt;action android:name="android.intent.action.MAIN" /> &lt;category android:name="android.intent.category.LAUNCHER" /> &lt;/intent-filter> &lt;/activity> &lt;activity android:name=".ActivityB" android:launchMode="singleTop" android:label="Activity B" android:taskAffinity="activity.B"> &lt;/activity> &lt;/application> &lt;/manifest> </pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload