简体   繁体   English

启用通知访问时未调用应用程序 onCreate

[英]Application onCreate not called when Notification Access Enabled

My Application onCreate is not calling when the notification access enabled.It calls only when I update the app or When I disable the notification access of my app.Here are the scenarios I found by debugging the app.我的Application onCreate在启用通知访问时不调用。它仅在我更新应用程序或禁用我的应用程序的通知访问权限时调用。以下是我通过调试应用程序发现的场景。

Condition 1 - onCreate Not Calling when Notification Access Enabled条件 1 - 启用通知访问时不调用 onCreate

i) I tried to kill the app.But Application onCreate not called i) 我试图杀死该应用程序。但未调用 Application onCreate

ii) It calls only One time when the app is launching ii) 仅在应用程序启动时调用一次

Condition 2 - onCreate called条件 2 - onCreate 调用

i) It calls when I kill the app i) 当我杀死应用程序时它会调用

ii) Notification Access disabled ii) 通知访问已禁用

When you open the activity onCreate will execute once.当您打开活动 onCreate 将执行一次。 So next time you open the same activity from Notification which you have already opened it wont execute the onCreate.So use onNewIntent因此,下次您从已打开的通知中打开相同的活动时,它不会执行 onCreate.So 使用 onNewIntent

manifest显现

<activity android:name="ActivityName" android:launchMode="singleTask">

then in your Activity然后在你的活动中

protected void onNewIntent(Intent intent) {
  super.onNewIntent(intent);
  //here you will get the intent
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM