Reputation: 659
I am trying to make an app which have 2 main controls (along with other info fields) 1.> Next button 2.> Done button
I want to call the same activity when next button is pressed and display some other activity when Done button is pressed
Done button is working fine. But when I press Next button the app stops working. The error that I get is : Unfortunately, myapp has stopped working
This is the same error which I usually get when I don't define activity in manifest file. Can anyone please help me with this problem.
And finally Is is legitimate to call same activity within itself ?
Thanks
Upvotes: 6
Views: 17026
Reputation: 7077
Intent i= new Intent(ActivityA.this,ActivityA.class);
startActivity(i);
or
startActivity(new Intent(ActivityA.this,ActivityA.class));
Upvotes: 0
Reputation: 8576
Try this
Intent intent= getIntent();
finish();
startActivity(intent);
Thank you
Upvotes: 2
Reputation: 24031
Why do you need to call the Activity within itself?
You can do following things:
1. You can reset data on next button click.
2. You can hide view or make visible on next button click.
Clear your requirements and show your code to check why the error Unfortunately, myapp has stopped working
is coming.
Upvotes: 1
Reputation: 1851
You can use Intent flags
to call the activity again. In the button
click
setContentView(R.layout.main);
Intent intent= new Intent(this,SameClass.class);
startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
Upvotes: 10
Reputation: 13825
I think this should work
Intent i= new Intent(ActivityA.this,ActivityA.class);
Upvotes: 11
Reputation: 1
Use TabGroupactivity
In the next button onclick write
public void next(View v) {
Intent next= new Intent(getParent(), next.class);
TabGroupActivity parentActivity = (TabGroupActivity) getParent();
parentActivity.startChildActivity("next", next);
}
Upvotes: 0