-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathMainActivity.java
61 lines (49 loc) · 1.82 KB
/
MainActivity.java
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
58
59
60
61
package com.morihacky.android.rxjava;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import com.morihacky.android.rxjava.fragments.MainFragment;
import com.morihacky.android.rxjava.fragments.RotationPersist1WorkerFragment;
import com.morihacky.android.rxjava.fragments.RotationPersist2WorkerFragment;
import com.morihacky.android.rxjava.rxbus.RxBus;
public class MainActivity
extends FragmentActivity {
private RxBus _rxBus = null;
@Override
public void onBackPressed() {
super.onBackPressed();
_removeWorkerFragments();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.replace(android.R.id.content, new MainFragment(), this.toString())
.commit();
}
}
// This is better done with a DI Library like Dagger
public RxBus getRxBusSingleton() {
if (_rxBus == null) {
_rxBus = new RxBus();
}
return _rxBus;
}
private void _removeWorkerFragments() {
Fragment frag = getSupportFragmentManager().findFragmentByTag(RotationPersist1WorkerFragment.class.getName());
if (frag != null) {
getSupportFragmentManager()
.beginTransaction()
.remove(frag)
.commit();
}
frag = getSupportFragmentManager().findFragmentByTag(RotationPersist2WorkerFragment.class.getName());
if (frag != null) {
getSupportFragmentManager()
.beginTransaction()
.remove(frag)
.commit();
}
}
}