我已经连接到Google Cloud Messaging,并在收到内容时显示通知。 我想在用户点击通知时“最大化”我的应用程序。即显示与我的应用程序相关的最新活动。或者,如果应用尚未开始,我想开始它的主要活动。当用户点击Android中的通知时显示应用
如果应用程序已经打开,则不必创建最后一个活动的新实例。
我该如何做到这一点?
我见过很多类似的问题,但所有的答案似乎都想指定活动类,我不知道,因为我不知道上一次显示哪个活动。
有没有解决这个看似简单的任务?
我的代码看起来像这样的时刻:
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon)
.setContentTitle("foo")
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0));
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
但它无法正常工作。
使用应用程序的registerLifecycleCallbacks来监视活动 –
你能否扩大其活动最后这个?点击方形按钮以获得运行应用程序的概述时,Android OS如何实现“最大化”? – HelloWorld
呃什么方形按钮 –