HeWhoProtects
HeWhoProtects

Reputation: 487

Notification status bar pressed to continue from last activity from a closed program

public void notification_status(Activity activity, String title, String details)
{
        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) activity.getSystemService(ns);
        int icon = R.drawable.bulogo;
        CharSequence tickerText = "My App";
        long when = System.currentTimeMillis();

        Notification notification = new Notification(icon, tickerText, when);
        Context context = activity.getApplicationContext();
        CharSequence contentTitle = title;
        CharSequence contentText = details;

      ----->  Intent notificationIntent = new Intent(activity, ???????);
        PendingIntent contentIntent = PendingIntent.getActivity(activity, 0, notificationIntent, 0);

        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
        notification.sound = Uri.parse("android.resource://com.champloo.mugen/" + R.raw.beep);

        mNotificationManager.notify(1, notification);
}

Hello guys I made this method so that I call it anywhere in my app to post a notification on the status bar, am not sure how to tell the program to return to its last activity if the user closed the program momentally....and pressed the notification under status bar.

Please help!

Upvotes: 1

Views: 385

Answers (1)

Prabu
Prabu

Reputation: 1441

Just use the same intent filters as android uses when launches the app:

    final Intent notificationIntent = new Intent(context, YourActivity.class);
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

As the intent you created to open your activity from notification bar is the same as android used for launching your app, the previously opened activity will be shown instead of creating a new one.

Upvotes: 3

Related Questions