[英]android: bring current activity to front via notification
i know there are numerous questions about this, but they didn't help me. 我知道对此有很多问题,但它们并没有帮助我。 At some Point my app creates a notification and i want it to bring the current app to the front without creating a new one. 在某个时间点,我的应用程序创建了一条通知,我希望它将当前应用程序置于最前面而不创建新的通知。
My Code(inside MainActivty): 我的代码(在MainActivty内部):
Intent intent = new Intent(this,MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Titel")
.setContentText("Text")
.addAction(new NotificationCompat.Action(R.mipmap.ic_launcher, "Testtitel",
pendingIntent));
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(0,builder.build());
the notfication is shown correctly but clicking on it has no effect. 通知已正确显示,但单击它无效。 What am i doing wrong? 我究竟做错了什么?
I am using notification in my application and if a particular notification is received I am directly opening my activity like below 我在我的应用程序中使用通知,如果收到特定通知,我将直接打开我的活动,如下所示
if (notification_type.equalsIgnoreCase("3")) {
Log.d(TAG, "Notification: " + "Before Meeting");
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.ON_AFTER_RELEASE, "MyWakeLock");
wakeLock.acquire();
KeyguardManager km = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
final KeyguardManager.KeyguardLock kl = km.newKeyguardLock("MyKeyguardLock");
kl.disableKeyguard();
Intent intentToMain = new Intent(this, MainActivity.class);
intentToMain.putExtra("destroy", "destroy");
intentToMain.addFlags(intentToMain.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentToMain);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.