我正在使用android兼容包来使用Loaders。当我初始化一个加载器或者在onCreate
方法中重新启动它时,它只是冒了查找但是当我重新启动或在onStart
中启动它时会抛出一个错误,我想要知道为什么“有时”我在活动的onCreate
中使用initLoader并单击某个按钮,在加载器将数据绑定到UI之前将其快速移动到另一个活动,然后返回到之前初始化Loader的活动,加载程序不加载数据UI上没有显示任何内容?!!!!所以我认为将initLoader移动到onStart
但是它会抛出错误
07-13 03:19:15.140: E/AndroidRuntime(23179): java.lang.RuntimeException: Unable to resume activity {biz.dot.khtmeh/biz.dot.khtmeh.ui.HomeScreen}: java.lang.IllegalStateException: There is already a listener registered
07-13 03:19:15.140: E/AndroidRuntime(23179): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2444)
07-13 03:19:15.140: E/AndroidRuntime(23179): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2472)
07-13 03:19:15.140: E/AndroidRuntime(23179): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1173)
07-13 03:19:15.140: E/AndroidRuntime(23179): at android.os.Handler.dispatchMessage(Handler.java:99)
07-13 03:19:15.140: E/AndroidRuntime(23179): at android.os.Looper.loop(Looper.java:137)
07-13 03:19:15.140: E/AndroidRuntime(23179): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-13 03:19:15.140: E/AndroidRuntime(23179): at java.lang.reflect.Method.invokeNative(Native Method)
07-13 03:19:15.140: E/AndroidRuntime(23179): at java.lang.reflect.Method.invoke(Method.java:511)
07-13 03:19:15.140: E/AndroidRuntime(23179): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-13 03:19:15.140: E/AndroidRuntime(23179): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-13 03:19:15.140: E/AndroidRuntime(23179): at dalvik.system.NativeStart.main(Native Method)
07-13 03:19:15.140: E/AndroidRuntime(23179): Caused by: java.lang.IllegalStateException: There is already a listener registered
07-13 03:19:15.140: E/AndroidRuntime(23179): at android.support.v4.content.Loader.registerListener(Loader.java:130)
07-13 03:19:15.140: E/AndroidRuntime(23179): at android.support.v4.app.LoaderManagerImpl$LoaderInfo.start(LoaderManager.java:259)
07-13 03:19:15.140: E/AndroidRuntime(23179): at android.support.v4.app.LoaderManagerImpl.installLoader(LoaderManager.java:509)
07-13 03:19:15.140: E/AndroidRuntime(23179): at android.support.v4.app.LoaderManagerImpl.createAndInstallLoader(LoaderManager.java:496)
07-13 03:19:15.140: E/AndroidRuntime(23179): at android.support.v4.app.LoaderManagerImpl.restartLoader(LoaderManager.java:642)
答案 0 :(得分:4)
您可能不止一次重复使用加载程序。每次调用onCreateLoader(..)
时,您都应该返回Loader<T>
的新实例。