1

I am facing a very strange issue in Android.

I have created an Android application,so when I install app to device from Eclipse it works fine, shows no issue. But when I save the apk file in phone memory or SD card (or via email) and then install the apk file on device it shows an issue.

When I open the app it works fine but when I minimize it & start from applications the app again restarts from its first activity (not from where I left) but if I open app from recent apps it starts from where I left.

I am really not getting what is the problem.

Please help.

Arun Badole
  • 10,977
  • 19
  • 67
  • 96

2 Answers2

2

It's because a different flag is set when starting from eclipse, and different one when starting from package installer.

try this:

1) copy APK to device
2) run APK and install application but don't choose "Open" when installation is over
3) close package installer
4) run your application from launcher

it should work exactly as from eclipse

Tomislav Novoselec
  • 4,570
  • 2
  • 27
  • 22
  • Great it works.I followed what you said.But how to solve this issue & how would user come to know it has to start from launcher only after installation. – Arun Badole Jul 26 '12 at 11:55
  • I don't think you can do anything here, because it's the system who is setting those flags.. i think it's the same issue as here: http://stackoverflow.com/questions/6356467/activity-stack-ordering-problem-when-launching-application-from-android-app-inst – Tomislav Novoselec Jul 26 '12 at 11:58
0

You can check flag FLAG_ACTIVITY_BROUGHT_TO_FRONT in onCreate() of your first activity and then finishing if it is set.

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
    // Here activity is brought to front, not created,
    // so finishing this will get you to the last viewed activity
    finish();
    return;
    }

// Regular code.
}