When I get a message I need to bring the activity to front. I use the following code:
public void BringToFront()
{
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
intent.setClass(getApplicationContext(), getClass());
startActivity(intent);
}
When I get the activity on top the previous data is lost, even though the activity was not killed by the OS. Is there a way to get the activity back without losing the data or I need to recover the data anyway?
Thanks
Your code doesn’t work. Your Activity is only active when it’s in front. If it’s not in front, it can’t process so your method will never be called. An Activity should always save the data it wants to keep, either in onSaveInstanceState or when the data is changed. There’s many ways to save data between activities.
If you want your activity to be in front, you’ll have to close all activities that are on top of it. If you need these activities again, you should have them save their data, and start them again with the new data.
I suggest you read the documentation on how Activities work….