質問

I have a simple application with a listview. When a user taps on a list item, i start a new activity

Intent eventdetails = new Intent(HomeActivity.this,EventDetailsActivity.class);
eventdetails.putExtra("eventId", ev.getId());
eventdetails.putExtra("eventDate", ev.getEnglishDate());
startActivity(eventdetails);

As soon as the EventDetailsActivity is started, the HomeActivity is destroyed (onDestroy is called). WHen the user hits the back button from EventDetailsActivity, the HomeActivity is recreated which is something i do not want.

I havent been able to figure out why the HomeActivity is killed in the first place. I checked the activity stack using udb as well and it does not show the HomeActivity

Running activities (most recent first):
Run #0: ActivityRecord{43938cc8 com.app.event/.EventDetailsActivity}

This is happening only on Samsung Galaxy Note 2

Any idea why this would be happening ?

役に立ちましたか?

解決

this will happen when the user has enabled this setting

goto settings->Developer options

in that in APPS category(scroll down to see), see the option
Don't keep Activities (Destroy every Activity as soon as user leaves it).

see this option is selected or not

他のヒント

Intent eventdetails = new Intent(HomeActivity.this,EventDetailsActivity.class);
eventdetails.putExtra("eventId", ev.getId());
eventdetails.putExtra("eventDate", ev.getEnglishDate());
eventdetails.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
eventdetails.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(eventdetails);
HomeActivity.this.finish();

try this code let me know if its help you

Maybe that'll be useful for someone - in my case the problem was that the parent activity was defined in the manifest with

android:noHistory="true"

With this setting it was killed as soon as the new activity was opened. See How does android:noHistory="true" work?

its because android manages the process of release activities,if you want to finish the previous activity,then add this after start activity:

HomeActivity.this.finish();

either you can you use flag to clear previous activities

eventdetails.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
eventdetails.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

or both:

Intent eventdetails = new Intent(HomeActivity.this,EventDetailsActivity.class);
eventdetails.putExtra("eventId", ev.getId());
eventdetails.putExtra("eventDate", ev.getEnglishDate());
eventdetails.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
eventdetails.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(eventdetails);
HomeActivity.this.finish();

hope it will help to resolve the issue.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top