My app creates a Notification from an IntentService. When tapped, the Notification opens MainActivity of type Activity. MainActivity's onCreate() method is called every time a newNotification is tapped, irrespective of whether an instance ofMainActivity is already created or not. Tapping the Notification always creates a new instance that replaces the old one.
Is there a way to call onCreate() only if the Activity doesn't exist and call e.g. onNewIntent() if MainActivity already exists (or another appropriate method) ?
The Notification is currently created like this:
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(com.exampleapp.myclient.R.drawable.dummy_notification_icon, "Notification!", System.currentTimeMillis());
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
notification.setLatestEventInfo(context, notificationTitle, "test", pendingIntent);
notificationManager.notify(1, notification);
MainActivity in Manifest:
<activity android:name="com.exampleapp.myclient.MainActivity"
singleTop="true">
</activity>