I have a service with an ongoing notification. in the app itself I have two activities - HomeActivity
and SettingsActivity
.
Currently what I have is -> when the notification is clicked:
If the app is closed -> open the
HomeActivity
.If the current showing activity is
HomeActivity
, bring it to front without creating a new one.
Code:
resultIntent = new Intent(context, HomeActivity.class);
resultPendingIntent = PendingIntent.getActivity(context, (int) System.currentTimeMillis(), resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = mBuilder
.setSmallIcon(notificationData.getImageSrc()) // the status icon
.setTicker("HealthChecker") // the status text
.setWhen(System.currentTimeMillis()) // the time stamp
.setContentTitle("HealthChecker") // the label of the entry
.setContentText(notificationData.getText()) // the contents of the entry
.setOngoing(true).setContentIntent(resultPendingIntent)
.build();
Manifest: I added `android:launchMode="singleTop":
<activity
android:name=".ui.HomeActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTop"
android:theme="@style/AppTheme.NoActionBar"></activity>
The problem I have is:
when I am in the SettingsActivity
and I click the notification, it opens a new instance of HomeActivity
.
What I want is when the app is opened in either activity and notification is clicked -> show current activity, and if app is closed and notification is clicked, open new instance of HomeActivity
.