English 中文(简体)
广播接收器在改变屏幕定位后坠毁,不工作
原标题:Broadcast receiver crashes after changing screen orientation and do not work

I had 2 BroadcastReceivers for watching SMS status. Code:

//纽约总部-when the SMS has been sent纽约总部-
   registerReceiver(new BroadcastReceiver(){
        @Override
        public void onReceive(Context arg0, Intent arg1) {
        ...................
        ...................
        }, new IntentFilter(SENT));
    //纽约总部-when the SMS has been delivered纽约总部-
    registerReceiver(new BroadcastReceiver(){
        @Override
        public void onReceive(Context arg0, Intent arg1) {
        ...................
        ...................
        }, new IntentFilter(DELIVERED));

这两家接收器位于一个称为“信箱”的程序中。 一切工作都很出色,但以下情况令我失望。 当用户改变屏幕取向和投向一种例外情况时,申请被压制。 LogCat告诉我,该方案不想第二次登记广播接收人。 我认为,不存在问题,并增加了一个诱杀旗帜,以便今后在OnCreate(OnCreate)跳出电动。 但是,即使电离层监测系统(SMS)的号召第二次出现,第一次改变屏幕的定位,是LogCat的一个新征兆:

活动泄漏

一旦出现这种情况,就不可能跟踪SMS的状况,接收器不会工作。 但是,如果用户试图发挥并继续改变方向,则不管怎样,错误都不出现。

纽约总部

Who knows, what happened? The workaround like a block permission to change orientation not interesting. I need to understand what happened here and solve a current problem.

LOGcat

> 10-15 20:08:20.863: ERROR/ActivityThread(452): Activity
> com.example.android.Dima.MySoft has leaked IntentReceiver
> com.example.android.Dima.MySoft$3@40531880 that was originally
> registered here. 难道你没有向未出庭者发出呼吁吗? 10-15
> 20:08:20.863: ERROR/ActivityThread(452):
> android.app.IntentReceiverLeaked: Activity
> com.example.android.Dima.MySoft has leaked IntentReceiver
> com.example.android.Dima.MySoft$3@40531880 that was originally
> registered here. 难道你没有向未出庭者发出呼吁吗? 10-15
> 20:08:20.863: ERROR/ActivityThread(452): at
> android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:799)
> 10-15 20:08:20.863: ERROR/ActivityThread(452): at
> android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:575) 10-15
> 20:08:20.863: ERROR/ActivityThread(452): at
> android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:852)
> 10-15 20:08:20.863: ERROR/ActivityThread(452): at
> android.app.ContextImpl.registerReceiver(ContextImpl.java:839) 10-15
> 20:08:20.863: ERROR/ActivityThread(452): at
> android.app.ContextImpl.registerReceiver(ContextImpl.java:833) 10-15
> 20:08:20.863: ERROR/ActivityThread(452): at
> android.content.ContextWrapper.registerReceiver(ContextWrapper.java:318)
> 10-15 20:08:20.863: ERROR/ActivityThread(452): at
> com.example.android.Dima.MySoft.initSMS(MySoft.java:473) 10-15
> 20:08:20.863: ERROR/ActivityThread(452): at
> com.example.android.Dima.MySoft.onCreate(MySoft.java:263) 10-15
> 20:08:20.863: ERROR/ActivityThread(452): at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
> 10-15 20:08:20.863: ERROR/ActivityThread(452): at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785)
> 10-15 20:08:20.863: ERROR/ActivityThread(452): at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1842)
> 10-15 20:08:20.863: ERROR/ActivityThread(452): at
> android.app.ActivityThread.access$1500(ActivityThread.java:132) 10-15
> 20:08:20.863: ERROR/ActivityThread(452): at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
> 10-15 20:08:20.863: ERROR/ActivityThread(452): at
> android.os.Handler.dispatchMessage(Handler.java:99) 10-15
> 20:08:20.863: ERROR/ActivityThread(452): at
> android.os.Looper.loop(Looper.java:143) 10-15 20:08:20.863:
> ERROR/ActivityThread(452): at
> android.app.ActivityThread.main(ActivityThread.java:4268) 10-15
> 20:08:20.863: ERROR/ActivityThread(452): at
> java.lang.reflect.Method.invokeNative(Native Method) 10-15
> 20:08:20.863: ERROR/ActivityThread(452): at
> java.lang.reflect.Method.invoke(Method.java:507) 10-15 20:08:20.863:
> ERROR/ActivityThread(452): at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
> 10-15 20:08:20.863: ERROR/ActivityThread(452): at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 10-15
> 20:08:20.863: ERROR/ActivityThread(452): at
> dalvik.system.NativeStart.main(Native Method) 10-15 20:08:20.873:
> ERROR/ActivityThread(452): Activity com.example.android.Dima.MySoft
> has leaked IntentReceiver com.example.android.Dima.MySoft$4@40531f08
> that was originally registered here. Are you missing a call to
> unregisterReceiver()? 10-15 20:08:20.873: ERROR/ActivityThread(452):
> android.app.IntentReceiverLeaked: Activity
> com.example.android.Dima.MySoft has leaked IntentReceiver
> com.example.android.Dima.MySoft$4@40531f08 that was originally
> registered here. 难道你没有向未出庭者发出呼吁吗? 10-15
> 20:08:20.873: ERROR/ActivityThread(452): at
> android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:799)
> 10-15 20:08:20.873: ERROR/ActivityThread(452): at
> android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:575) 10-15
> 20:08:20.873: ERROR/ActivityThread(452): at
> android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:852)
> 10-15 20:08:20.873: ERROR/ActivityThread(452): at
> android.app.ContextImpl.registerReceiver(ContextImpl.java:839) 10-15
> 20:08:20.873: ERROR/ActivityThread(452): at
> android.app.ContextImpl.registerReceiver(ContextImpl.java:833) 10-15
> 20:08:20.873: ERROR/ActivityThread(452): at
> android.content.ContextWrapper.registerReceiver(ContextWrapper.java:318)
> 10-15 20:08:20.873: ERROR/ActivityThread(452): at
> com.example.android.Dima.MySoft.initSMS(MySoft.java:511) 10-15
> 20:08:20.873: ERROR/ActivityThread(452): at
> com.example.android.Dima.MySoft.onCreate(MySoft.java:263) 10-15
> 20:08:20.873: ERROR/ActivityThread(452): at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
> 10-15 20:08:20.873: ERROR/ActivityThread(452): at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785)
> ....

此外,还混淆了来自LOGCat的下一个短语。

难道你没有向未出庭者发出呼吁吗?

......为什么发生这种情况?

最佳回答

当用户改变时,屏幕取向和roid弃一种例外申请被抑制。

您应在onPause(>>上对接收人进行保留,并在onResume(>上登记。 这样,当安乐斯摧毁并重新调整组合改变的活动时,你仍将有接收者。

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签