English | 简体中文
An android library that automatically binds data carried by the Intent or Bundle.
Add to your root build.gradle:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency:
dependencies {
implementation 'com.github.ausboyue.IntentLife:intentlife:v1.0.4'
annotationProcessor 'com.github.ausboyue.IntentLife:intentlife_compiler:v1.0.4'
}
ActivityA jump to ActivityB
- ActivityA edit code maybe as below:
User user = new User();
user.setUserId("9527");
user.setName("Cheny");
user.setJob("android developer");
Intent intent = new Intent(activityA, ActivityB.class);
intent.putExtra("key_user", user);
startActivity(intent);
- ActivityB edit code as below:
public class ActivityB extends AppCompatActivity {
@BindIntentKey("key_user")
User mUser;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_secend);
// IntentLife inject
IntentLife.bind(this);
TextView tv_user_name = findViewById(R.id.tv_user_name);
tv_user_name.setText(
"Hello , I am " + mUser.getName()
+ ".\nMy job is " + mUser.getJob() + ".");
}
}
- Support java eight basic data types and their arrays and collections
- Classes that support the implementation of the Serializable interface
- Support for classes that implement Parcelable interfaces and their arrays and collections
- Support all data types supported by android Bundle
- Support jump between Activities
- Support loading Fragments
- Support for use in any class that needs to use data, such as the Presenter class in MVP design
The target field should not have the private
modifier, otherwise the data will not be bound with field.
If you find any bug when using it, please contact me. Thanks for helping me making better.
Cheny - @ausboyue on GitHub, @www.icheny.cn
Please give me some time to update the documentation ^_^