views:

154

answers:

1

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.)

+3  A: 

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.

mbaird