Android: Using Getintent() Only Within Oncreate?
In Android (targeting APIs 14-16) I have a MainActivity and a NextActivity. There is no difficulty using intents to start NextActivity from within MainActivity if the getIntent() m
Solution 1:
You can't getIntent()
before onCreate()
-- there's simply no Intent
available at that point. I believe the same is true for anything that requires a Context
.
Your anonymous inner class can still call getIntent()
, however, so you don't need to declare this as a variable at all.
Solution 2:
According to your question what i understand is u don't want to declare data as final in next activity..Then y cant u try for this./
publicclassNextActivityextendsActivity {
int data=0;
@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
data = this.getIntent().getIntExtra("data", 7);
...
}
...
}
Try this...
Post a Comment for "Android: Using Getintent() Only Within Oncreate?"