Android: How To Avoid That Clicking On A Notification Calls Oncreate()
Solution 1:
To bring your app to the foreground if it is running already you need to set different flags on your intent:
contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
For running a specific method you could just pass extra information along with the intent and interpret it in your application to decide which method to run.
Solution 2:
The recommendation to use FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_SINGLE_TOP only partially solves the problem. The activity in the Android manifest should also have these settings applied so that launching the activity from the home screen has the same behavior. Without these properties multiple instances of the activity can be launched.
<activityandroid:name="foo"android:clearTaskOnLaunch="true"android:launchMode="singleTop"android:label="@string/app_name">
Solution 3:
I've discovered that if you use Intent contentIntent = new Intent(this, ABC.class);
this calls onCreate();
regardless of the flags set.
Use Intent contentIntent = getIntent();
to skip onCreate();
and that moves to onStart();
Post a Comment for "Android: How To Avoid That Clicking On A Notification Calls Oncreate()"