Any ideas in the best way to send an IntDef through an Intent?
ps: If you simply send it as an int you loose the type check, which is the main goal of having the intdef
Any ideas in the best way to send an IntDef through an Intent?
ps: If you simply send it as an int you loose the type check, which is the main goal of having the intdef
Your IntDef is not available at runtime. The way to go is to encapsulate the generation of the intent in your intent-receiving Activity.
public class MyActivity extends Activity {
private static final String KEY_NAVIGATION_MODE = "navigation_mode";
private @NavigationMode int mNavigationMode;
public static Intent getStartIntent(Context context, @NavigationMode String navigationMode) {
Intent intent = new Intent(context, MyActivity.class);
intent.putExtra(KEY_NAVIGATION_MODE, navigationMode);
return intent;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//noinspection WrongConstant Safe because we saved it in #getStartIntent
mNavigationMode = getIntent().getIntExtra(KEY_NAVIGATION_MODE, NAVIGATION_MODE_YOUR_DEFAULT);
}
}