Android 完全退出的實例詳解
更新時間:2017年10月24日 09:40:30 作者:Adam289
這篇文章主要介紹了Android 完全退出的實例詳解的相關資料,希望通過本文能幫助到大家,讓大家掌握這部分內(nèi)容,需要的朋友可以參考下
Android 完全退出的實例詳解
首先,在基類BaseActivity里,注冊RxBus監(jiān)聽:
public class BaseActivity extends AppCompatActivity { Subscription mSubscription; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Utils.intiSySBar(this, R.color.colorblack); initRxBus(); } //接收退出的指令,關閉所有activity private void initRxBus() { mSubscription = RxBus.getInstance().toObserverable(NormalEvent.class) .subscribe(new Action1<NormalEvent>() { @Override public void call(NormalEvent userEvent) { if (userEvent.getType() == -1) { finish(); } } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { } }); } @Override protected void onDestroy() { super.onDestroy(); if (!mSubscription.isUnsubscribed()) { mSubscription.unsubscribe(); } } }
這是事件實體NormalEvent:
public class NormalEvent { private int type; public NormalEvent(int type) { this.type = type; } public int getType() { return type; } public void setType(int type) { this.type = type; } }
最后,在需要退出的地方調用:
RxBus.getInstance().post(new NormalEvent(-1));//發(fā)送退出指令
如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關文章
Android中Fragment的加載方式與數(shù)據(jù)通信詳解
本文主要介紹了Android中Fragment的加載方式與數(shù)據(jù)通信的相關知識。具有很好的參考價值。下面跟著小編一起來看下吧2017-03-03Android四大組件之BroadcastReceiver詳解
今天小編就為大家分享一篇關于Android四大組件之BroadcastReceiver詳解,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-01-01Android 個人理財工具一:項目概述與啟動界面的實現(xiàn)
本文主要介紹Android 開發(fā)個人理財工具項目概述與啟動界面的實現(xiàn),這里主要對實現(xiàn)項目的流程做了詳細概述,并對啟動界面簡單實現(xiàn),有需要的小伙伴可以參考下2016-08-08Android開啟閃光燈的方法 Android打開手電筒功能
這篇文章主要為大家詳細介紹了Android開啟閃光燈的方法,Android打開手電筒功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-07-07