application (non-wanted) behavior -
- application is started, some text is put into text-box and notification is created through button action.
- user "clicks" the home button, application is "minimized", notification is available in bar
- user selects the notification and the application is "maximized"
BUT - instead of the original instance, new instance is started (e.g. in the newest instance is missing the original text; when the latest instance is closed there is still the original instance with original text ) .
the code of the notification method
Context context = getApplicationContext();
CharSequence contentTitle = "someText1";
CharSequence contentText = "someText2";
Intent notifyIntent = new Intent(Intent.ACTION_MAIN);
notifyIntent.setClass(getApplicationContext(), RadioStream.class);
PendingIntent intent =
PendingIntent.getActivity(RadioStream.this, 0, notifyIntent, 0);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
i have also in the manifest xml file following tag
android:launchMode="singleTask"
but it is still the same... The main problem is double/triple initialization of the application, i know that there are other means to preserve the values in resumed applications. Also it is needed that the applications stays running in background as the main functionality is the streaming of internet radio.
What is missing in the code ? What kind of information from my side is missing for to troubleshoot the issue ?
Thanks!
Dav
What you refer as "application" is most probably an Activity. To avoid re-crating it when bringing up to front, use
To have some code running background, you need to realize it as Service
I used GCM example as base code for a personal project and I faced the same issue described on top. GCM Example: https://github.com/googlesamples/google-services/tree/master/android/gcm/app/src/main/java/gcm/play
I found a solution by combining to answers:
1) From @ognian answer, by adding to App Manifest on application section:
android:launchMode="singleTop"
2) From @CommonsWare by setting setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP)
This will bring the app back to its MainActivity even if it has opened child activities. Child activities are also cleared.
AndroidManifest:
Code: