我有一个android的phonegap应用程序。 我正在尝试使用插件进行GCM通知,但如果我注册设备,当我关闭应用程序时,我在控制台中出现此错误:
11-17 16:51:43.457:E / ActivityThread(12552):活动org.apache.cordova.example.MainActivity有 泄露了IntentReceiver 那是com.google.android.gcm.GCMBroadcastReceiver@405a7158 最初在这里注册。你错过了一个电话吗? unregisterReceiver()? 11-17 16:51:43.457:E / ActivityThread(12552): android.app.IntentReceiverLeaked:Activity org.apache.cordova.example.MainActivity泄露了IntentReceiver 那是com.google.android.gcm.GCMBroadcastReceiver@405a7158 最初在这里注册。你错过了一个电话吗? unregisterReceiver()? 11-17 16:51:43.457:E / ActivityThread(12552):at android.app.LoadedApk $ ReceiverDispatcher。(LoadedApk.java:756) 11-17 16:51:43.457:E / ActivityThread(12552):at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:551)11-17 16:51:43.457:E / ActivityThread(12552):at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:860) 11-17 16:51:43.457:E / ActivityThread(12552):at android.app.ContextImpl.registerReceiver(ContextImpl.java:847)11-17 16:51:43.457:E / ActivityThread(12552):at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:325) 11-17 16:51:43.457:E / ActivityThread(12552):at com.google.android.gcm.GCMRegistrar.setRetryBroadcastReceiver(GCMRegistrar.java:276) 11-17 16:51:43.457:E / ActivityThread(12552):at com.google.android.gcm.GCMRegistrar.register(GCMRegistrar.java:202) 11-17 16:51:43.457:E / ActivityThread(12552):at com.plugin.GCM.GCMPlugin.execute(GCMPlugin.java:63)11-17 16:51:43.457:E / ActivityThread(12552):at org.apache.cordova.api.CordovaPlugin.execute(CordovaPlugin.java:61) 11-17 16:51:43.457:E / ActivityThread(12552):at org.apache.cordova.api.PluginManager.exec(PluginManager.java:220) 11-17 16:51:43.457:E / ActivityThread(12552):at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:44)11-17 16:51:43.457:E / ActivityThread(12552):at android.webkit.LoadListener.nativeFinished(Native Method)11-17 16:51:43.457:E / ActivityThread(12552):at android.webkit.LoadListener.nativeFinished(Native Method)11-17 16:51:43.457:E / ActivityThread(12552):at android.webkit.LoadListener.tearDown(LoadListener.java:1579)11-17 16:51:43.457:E / ActivityThread(12552):at android.webkit.LoadListener.handleEndData(LoadListener.java:1041) 11-17 16:51:43.457:E / ActivityThread(12552):at android.webkit.LoadListener.handleMessage(LoadListener.java:362)11-17 16:51:43.457:E / ActivityThread(12552):at android.os.Handler.dispatchMessage(Handler.java:99)11-17 16:51:43.457:E / ActivityThread(12552):at android.os.Looper.loop(Looper.java:130)11-17 16:51:43.457: E / ActivityThread(12552):at android.webkit.WebViewCore $ WebCoreThread.run(WebViewCore.java:746) 11-17 16:51:43.457:E / ActivityThread(12552):at java.lang.Thread.run(Thread.java:1019)
在我的ActivityClass中,我有这段代码:
private BroadcastReceiver handleMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String newMessage = intent.getExtras().getString("message");
//sveglia il telefono se è in stand-by
WakeLocker.acquire(getApplicationContext());
//visualizza il messaggio
Toast.makeText(getApplicationContext(), "New Message: " + newMessage, Toast.LENGTH_LONG).show();
//rilascia il wavelocker
WakeLocker.release();
}
};
@Override
protected void onStart() {
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.CATEGORY_APP_MESSAGING);
registerReceiver(handleMessageReceiver, intentFilter);
super.onStart();
}
@Override
protected void onStop() {
if(handleMessageReceiver != null) {
unregisterReceiver(handleMessageReceiver);
handleMessageReceiver = null;
}
super.onStop();
}
@Override
public void onDestroy() {
try{
unregisterReceiver(handleMessageReceiver);
GCMRegistrar.onDestroy(this);
}catch(Exception e) {
}
super.onDestroy();
}
我在javascript文件中使用此命令关闭应用程序:
navigator.app.exitApp();
我有忘记的事吗?