BaseRxActivity.java
1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.hjx.parent.rx;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.viewbinding.ViewBinding;
import com.hjx.parent.BaseActivity;
import com.trello.rxlifecycle2.android.ActivityEvent;
import io.reactivex.subjects.BehaviorSubject;
public abstract class BaseRxActivity<VB extends ViewBinding> extends BaseActivity<VB> implements ILifecycleActivity {
private BehaviorSubject<ActivityEvent> rxLifecycle = BehaviorSubject.create();
@Override
public BehaviorSubject<ActivityEvent> getRxLifecycle() {
return rxLifecycle;
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
rxLifecycle.onNext(ActivityEvent.CREATE);
}
@Override
protected void onStart() {
super.onStart();
rxLifecycle.onNext(ActivityEvent.START);
}
@Override
protected void onResume() {
super.onResume();
rxLifecycle.onNext(ActivityEvent.RESUME);
}
@Override
protected void onPause() {
super.onPause();
rxLifecycle.onNext(ActivityEvent.PAUSE);
}
@Override
protected void onStop() {
super.onStop();
rxLifecycle.onNext(ActivityEvent.STOP);
}
@Override
protected void onDestroy() {
super.onDestroy();
rxLifecycle.onNext(ActivityEvent.DESTROY);
}
}