Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference Between 2 Ways to Start an Activity?

I have seen the following two examples of starting activities in Android:

Example 1

Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);
CurrentActivity.this.startActivity(myIntent);

Example 2

// Calling activity
NextActivity.show(this)

// In the called activity
static void show(Context context) {
        final Intent intent = new Intent(context, NextActivity.class);
        context.startActivity(intent);
}

It seems the obvious difference between the two examples is that you attach the logic of how an activity is created to the implementation of the activity. Are there any other key differences? (e.g. is the calling activity told to wait until the called activity finishes in one case, but not in the other, etc.)

like image 528
Marcus Avatar asked Dec 13 '25 12:12

Marcus


1 Answers

I see no difference to your 2 methods, other than the 2 lines of code in your first method just happen to be located in a static method that just happens to be located in the 2nd activity's class.

The actual lines of code that are being executed to start the activity are identical. Thus the behavior of the 2 methods will be identical.

like image 108
Mark B Avatar answered Dec 16 '25 23:12

Mark B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!