-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseActivity.java
More file actions
74 lines (58 loc) · 1.81 KB
/
BaseActivity.java
File metadata and controls
74 lines (58 loc) · 1.81 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.jocoo.common;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import butterknife.ButterKnife;
/**
* Created by Jocoo on 2016/10/20.
*/
public abstract class BaseActivity extends AppCompatActivity {
protected Context mContext;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityManagement.getInstance().addActivity(this);
preSetContentView();
setContentView(getLayoutId());
mContext = this;
ButterKnife.bind(this);
initView();
initData();
}
protected void preSetContentView() {
}
protected abstract int getLayoutId();
protected abstract void initView();
protected void initData() {
}
@Override
protected void onDestroy() {
super.onDestroy();
ButterKnife.unbind(this);
}
@Override
public void finish() {
super.finish();
}
protected void startActivity(Class<?> activity) {
startActivity(activity, null);
}
protected void startActivity(Class<?> activity, Bundle bundle) {
Intent intent = new Intent();
intent.setClass(this, activity);
if (bundle != null) {
intent.putExtras(bundle);
}
startActivity(intent);
}
protected void startActivityForResult(Class<?> activity, Bundle bundle, int requestCode) {
Intent intent = new Intent();
intent.setClass(this, activity);
if (bundle != null) {
intent.putExtras(bundle);
}
startActivityForResult(intent, requestCode);
}
}