I am having a problem with resuming activity on notification click. I have an app that plays a single song for some time. The idea is when you play a song, and press Home button, there should be notification that returns you to the app where you can stop the song.
Here is how I am making the notification:
private void pushNotificationsOld()
{
Intent resultIntent = new Intent(context, MainActivity.class);
resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationManager mNM;
NotificationCompat.Builder builder;
mNM = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(getResources().getString(R.string.app_name))
.setContentText("Now playing: " + songList.get(activeSong).name)
.setOngoing(true);
builder.setContentIntent(resultPendingIntent);
mNM.notify(mId, builder.build());
}
And here is my Manifest:
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
pushNotificationsOld() is called by pressing the Play button.
And there is only one activity in the app.
With this code, when I press notification, new activity is created, and the music continues playing in the background.
When I press Home and get back to app from recent apps or icon, it worsk good.