Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android通知。如何重新打开以前的活动?_Android - Fatal编程技术网

Android通知。如何重新打开以前的活动?

Android通知。如何重新打开以前的活动?,android,Android,这是一个媒体播放器,每次我单击home(主页)按钮,它都会转到onPause(暂停) 音乐仍在播放,搜索栏仍在运行,每次我的活动处于暂停状态时,它都会打开通知,当我单击通知时,它会再次返回我的活动 问题是,每次我单击它,它都会启动一个新的活动并重置所有内容。我想让它恢复上一个仍在运行的活动。您需要使用服务播放音乐。这应该是一个将从另一个服务启动并在绑定服务发行版上停止的活动。您需要仔细阅读文档:& @Override protected void onPause() { Intent n

这是一个媒体播放器,每次我单击home(主页)按钮,它都会转到onPause(暂停) 音乐仍在播放,搜索栏仍在运行,每次我的活动处于暂停状态时,它都会打开通知,当我单击通知时,它会再次返回我的活动


问题是,每次我单击它,它都会启动一个新的活动并重置所有内容。我想让它恢复上一个仍在运行的活动。

您需要使用服务播放音乐。这应该是一个将从另一个服务启动并在绑定服务发行版上停止的活动。

您需要仔细阅读文档:&
@Override
protected void onPause() {
    Intent notificationIntent = new Intent(getBaseContext(), Music.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(getBaseContext(), 0, notificationIntent, 0);

    Notification n  = new Notification.Builder(Music.this)
            .setContentTitle("Music PLayer")
            .setContentText("Subject")
            .setContentIntent(intent)
            .setSmallIcon(R.drawable.icon)
            .setAutoCancel(true).build();
    NotificationManager notificationManager = 
      (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(0, n);
    super.onPause();
}