Yordan Yanakiev
Yordan Yanakiev

Reputation: 2604

Prevent main activity from pausing while other activity is opened?

Upvotes: 0

Views: 2187

Answers (3)

DArkO
DArkO

Reputation: 16110

The activity is not destroying the content on pause. it does do that on onDestroy. You are probably rotating the screen which causes the bottom activity to re-create. you need to save state if you want to preserve the content.

Upvotes: 1

TronicZomB
TronicZomB

Reputation: 8747

No. That is the lifecycle of an Activity. As soon as the view is obstructed then the Activity will pause, once it is completely hidden it will stop, at which point Android can destroy it at any time to reallocate resources for other Activities.

This helped me understand more.

Upvotes: 2

codeMagic
codeMagic

Reputation: 44571

You can't keep the Activity from pausing because it needs to follow the Activity Lifecycle but you can override onPause() and save whatever you need

@Override
public void onPause()
{
    // save your data
}

How you save the content depends on what you need. But if you are going to an activity and coming right back then you would want to use startActivityForResult() to accomplish this

Upvotes: 2

Related Questions