Answer the question
In order to leave comments, you need to log in
How is it more correct from a logical and aesthetic point of view to open a new Activity?
1 option:
@Override
protected void onCreate(Bundle savedInstanceState) {
...
Button firstButton = (Button) findViewById(R.id.firstButton);
firstButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Context context = view.getContext();
Intent intent = new Intent(context, secondActivity.class);
context.startActivity(intent);
}
});
...
}
public void buttonClick(View view){
Intent intent = new Intent(this, secondActivity.class);
startActivity(intent);
}
Answer the question
In order to leave comments, you need to log in
The second option has a margin for the future - if you need to call activities from different places, perform some additional actions, then the code will be more concise in the end.
PS In a good way, the Intent for the call should be returned by the called activity.
From an aesthetic and logical point of view, it is correct to create a Router class, which will contain the openSomeScreen () method, and which will be called from all the right places.
You most likely don't need two activities, you need fragments.
The activity/fragment code should contain the necessary minimum of actions.
I agree with Denis Zagaevsky . After all, it is considered good form to have one activity and many fragments. Google IO 2019 showed Navigation Architecture Components and encouraged to use Single Activity, because Activity is an entry point, and it should be one
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question