-
Notifications
You must be signed in to change notification settings - Fork 31
Introdution
MarcinMoskala edited this page Feb 10, 2017
·
1 revision
Let's look at the example. This is Activity made in standard way:
public class MainActivity extends BaseActivity {
@UiThread
public static void start(Context context, String name, int id, char grade, boolean isPassing) {
Intent intent = new Intent(context, StudentDataActivity.class);
intent.putExtra("nameArg", name);
intent.putExtra("idArg", id);
intent.putExtra("gradeArg", grade);
intent.putExtra("isPassingArg", isPassing);
context.startActivity(intent);
}
String name;
int id;
char grade;
boolean isPassing;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
name = intent.getStringExtra("nameArg");
id = intent.getIntExtra("idArg", -1);
grade = intent.getCharExtra("gradeArg", 'a');
isPassing = intent.getBooleanExtra("isPassingArg", false);
}
}
And we start it by:
MainActivity.start(context, name, id, grade, isPassing);
With ActivityStarter all you need is:
public class MainActivity extends BaseActivity {
@Arg String name;
@Arg int id;
@Arg char grade;
@Arg boolean isPassing;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityStarter.start(this); // This can be located in BaseActivity, one for all activities
//...
}
}
And you start it nearly the same way:
MainActivityStarter.start(context, name, id, grade, isPassing);
Simillar way you can take Intent or start activity with flags:
MainActivityStarter.getIntent(context, name, id, grade, isPassing);
MainActivityStarter.startWithFlags(context, name, id, grade, isPassing, FLAG_ACTIVITY_SINGLE_TOP);
This are only simple examples of SuperActivity usage. It is helping to make code concise and more readable. Library is providing also lot's of other possibilities.