按下通知状态栏以从已关闭程序的上一个活动继续

时间:2012-04-18 18:56:23

标签: android notifications android-activity

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);
}

大家好我制作了这个方法,以便在应用程序的任何地方调用它,在状态栏上发布通知,如果用户暂时关闭程序,我不知道如何告诉程序返回上一个活动。 ..并按状态栏下的通知。

请帮忙!

1 个答案:

答案 0 :(得分:3)

启动应用时,只需使用Android使用的相同意图过滤器:

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

由于您从通知栏打开活动所创建的意图与用于启动应用程序的Android相同,因此将显示先前打开的活动,而不是创建新活动。