0

enter image description here

The setup:

  • I have 9 Fragments placed inside MainActivity.
  • There is a seperate background service which has a notification active all the time while it's alive. (Playing audio)
  • After application is closed with the home button, touching the notification opens the application.
  • When a certain object is selected inside a fragment (audio track), a new Activity is loaded (NowplayingActivity)

What I need:

  • I want everything the same, except, I want the system to open MainActivity first, than, NowplayingActivity when notification is touched.

What I tried:

  • *I couldn't make TaskStackBuilder work correctly.(Maybe it is not for this kind of stuff) MainActivity is never shown (but the NowplayingActivity) even though I have parentActivity defined in manifest file.

    • I tried passing a logical command in Intent's extras ("when you are created, open NowplayingActivity"). This works. But as onNewIntent is called before Fragments on the MainActivity created completely, fragments do not receive hints for visibility changes and also they are not paused... I can delay the launch of the other Activity while inside onNewIntent, but this is ugly.

What can I try? What am I missing here?

update (added non-working code for the TaskStackBuilder method) *

<activity
        android:name=".MainActivity"
        android:launchMode="singleInstance"
        android:label="MMM"
        android:parentActivityName=".MainActivity">
...
<meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value=".MainActivity"/>

.

Intent resultIntent = new Intent(this, NowplayingActivity.class);          
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);  
stackBuilder.addParentStack(NowplayingActivity.class); 
stackBuilder.addNextIntent(resultIntent);

//PendingIntent resultPendingIntent = PendingIntent.getActivity( this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);

PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
frankish
  • 6,738
  • 9
  • 49
  • 100

0 Answers0