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
Yes it is. If your requirement are like that then there is no harm in doing that. If you use this then dont forget to call finish(). finish() will remove the activity from backstack so when you press back you dont return to previous instance of same activity.
If you start the activity with startActivityForResult(Intent, int) , then you can get calling activity by getCallingActivity(). getClassName() .
Start the Second Activity To start an activity, call startActivity() and pass it your Intent . The system receives this call and starts an instance of the Activity specified by the Intent .
onDestroy( ) is called before the activity is destroyed. The system invokes this callback either because: the activity is finishing (due to the user completely dismissing the activity or due to finish( ) being called on the activity), or.
I think this should work
Intent i= new Intent(ActivityA.this,ActivityA.class);
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With