相关疑难解决方法(0)

使用带有保留片段的Otto时出现IllegalArgumentException

我正在使用Otto 1.3.3,当我恢复我的应用程序时,我有时会得到IllegalArgumentException以下堆栈跟踪:

Caused by: java.lang.IllegalArgumentException: Producer method for type class 
com.couchsurfing.mobile.ui.setup
        .SessionProviderFragment$SessionConnectionStateChangeEvent found on 
        type class com.couchsurfing.mobile.ui.setup.SessionProviderFragment, 
        but already registered by type class 
        com.couchsurfing.mobile.ui.setup.SessionProviderFragment.
    at com.squareup.otto.Bus.register(Bus.java:194)
    at com.couchsurfing.mobile.ui.BaseRetainedFragment
       .onCreate(BaseRetainedFragment.java:20)
Run Code Online (Sandbox Code Playgroud)

SessionProviderFragment有它的实例保留,请找扩展的类如下所示:

public abstract class BaseRetainedFragment extends SherlockFragment {

    @Inject
    Bus bus;

    @Override
    public void onCreate(final Bundle state) {
        super.onCreate(state);
        ((CouchsurfingApplication) getActivity().getApplication()).inject(this);
        setRetainInstance(true);
        bus.register(this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        bus.unregister(this);
        bus = null;
    }
}
Run Code Online (Sandbox Code Playgroud)

我试过使用bus.register(this)in onAttach()或者onCreate()没有改变这个问题.

android android-lifecycle otto

7
推荐指数
2
解决办法
2965
查看次数

Android:何时取消注册侦听器 - onStop()或onDestroy()

关于何时unregisterListener为传感器管理器,我有基本的问题.是应该在onStop()onDestroy().

用例:

我想accelorometer点击开始按钮记录,当用户点击停止按钮时停止.数据的频率是每分钟.所以我开始了timer.

但问题是,每次orientation根据Android架构进行更改onStop()都会被调用.在onStop()我取消计时器和取消注册听众.

再次如果我在onResume()频率中启动定时器/寄存器监听器将不会保持1分钟并且在没有用户按下开始按钮的情况下记录数据.

有人可以帮我解决这个问题.

谢谢.

android

5
推荐指数
1
解决办法
5279
查看次数

标签 统计

android ×2

android-lifecycle ×1

otto ×1