r/androiddev • • Nov 26 '16

Effective Java for Android (cheatsheet)

https://medium.com/rocknnull/effective-java-for-android-cheatsheet-bf4e3433889a
223 Upvotes

49 comments sorted by

View all comments

32

u/Plastix Nov 26 '16 edited Nov 26 '16

Static factory methods are really good for creating intents as well:

public class MyActivity {

	private static final String EXTRA_ARG = "SomeArg";
	
	public static Intent newIntent(Context context, String someArg){
		Intent intent = new Intent(context, MyActivity.class);
		intent.putString(EXTRA_ARG, someArg);

		return intent;
	}
}

Great writeup! Thanks for sharing.

10

u/ditn Google Developer Expert Nov 26 '16

There's a shortcut/postfix completion thing in Android Studio to do this for you. Type 'start' on a new line.

1

u/aselims Jan 26 '17

'starter' is the right one at AS2.2.3