android:通过通知将当前活动带到前台

android:通过通知将当前活动带到前台,android,Android,我知道关于这件事有很多问题,但他们没有帮助我。 在某个时刻,我的应用程序会创建一个通知,我希望它能够在不创建新应用程序的情况下将当前应用程序带到前台 我的代码(主活动内): 注释显示正确,但单击它无效。我做错了什么?我在应用程序中使用通知,如果收到特定通知,我将直接打开我的活动,如下所示 if (notification_type.equalsIgnoreCase("3")) { Log.d(TAG, "Notification: " + "Be

我知道关于这件事有很多问题,但他们没有帮助我。 在某个时刻,我的应用程序会创建一个通知,我希望它能够在不创建新应用程序的情况下将当前应用程序带到前台

我的代码(主活动内):


注释显示正确,但单击它无效。我做错了什么?

我在应用程序中使用通知,如果收到特定通知,我将直接打开我的活动,如下所示

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

                }

当收到通知时,您可以使用INTENTS将页面转移到活动中,我使用
.setContentIntent(PendingContent)使其工作而不是
addAction
     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);

                }