Android 完全退出的實(shí)例詳解
Android 完全退出的實(shí)例詳解
首先,在基類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();
}
//接收退出的指令,關(guān)閉所有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();
}
}
}
這是事件實(shí)體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;
}
}
最后,在需要退出的地方調(diào)用:
RxBus.getInstance().post(new NormalEvent(-1));//發(fā)送退出指令
如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
Android使用kotlin實(shí)現(xiàn)多行文本上下滾動播放
這篇文章主要為大家詳細(xì)介紹了Android使用kotlin實(shí)現(xiàn)多行文本的上下滾動播放,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-01-01
Android編程開發(fā)之打開文件的Intent及使用方法
這篇文章主要介紹了Android編程開發(fā)之打開文件的Intent及使用方法,已實(shí)例形式分析了Android打開文件Intent的相關(guān)布局及功能實(shí)現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-10-10
Android List(集合)中的對象以某一個字段排序案例
這篇文章主要介紹了Android List(集合)中的對象以某一個字段排序案例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08
Android實(shí)現(xiàn) Shape屬性gradient 漸變效果
這篇文章主要介紹了Android 實(shí)現(xiàn)Shape屬性gradient 漸變效果,gradient用以定義漸變色,可以定義兩色漸變和三色漸變,及漸變樣式,具體實(shí)現(xiàn)代碼感興趣的朋友跟隨小編一起看看吧2019-11-11
Android實(shí)現(xiàn)仿微信tab高亮icon粘著手的滑動效果
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)仿微信tab高亮icon粘著手的滑動效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-08-08
Android studio 運(yùn)行main 函數(shù)的方法
這篇文章主要介紹了Android studio 運(yùn)行main 函數(shù)的方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-09-09

