Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application launch from splash everytime ( while closing with Home) when installing from sdcard with Open option

I have found very strange bug with any of the Android application, when we are installing the application in Android Device with given flow.

  1. Unistall the app if already installed.
  2. Download the app(.apk file) and keep in SD card
  3. Double click on the .apk file and tap on “Install” on Installation window
  4. In confirmation popup, tap on “Open” button (Please do not tap on “Done”)
  5. Now App will open then visit to some other activities ( In my case say...Splash ---> Login--> Home screen ).
  6. Now tap on the device Home button, it take me to the device main screen.
  7. Now if i again tap on the launcher icon, my app starts from the 1st screen ( i.e. Splash ). While it should display my app Home page.

Also in STEP: 4 if i choose Done option, then launching my application, then it is working fine.

is it an Android OS related bug? or am I doing something wrong?

Any suggestion in this regard really appreciated.

Thanks HImanshu

like image 520
Himanshu Avatar asked Apr 05 '14 11:04

Himanshu


2 Answers

This solution worked for me,

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
        // Activity was brought to front and not created,
        // Thus finishing this will get us to the last viewed activity
        finish();
        return;
    }
like image 187
Nayan Avatar answered Oct 13 '22 10:10

Nayan


I solved this with adding this code in SplashActivity's onCreate:

 if (!isTaskRoot()
                && getIntent().hasCategory(Intent.CATEGORY_LAUNCHER)
                && getIntent().getAction() != null
                && getIntent().getAction().equals(Intent.ACTION_MAIN)) {

            finish();
            return;
        }

If anyone can find source of this, please let me know - I can't find the original answer I got this from.

like image 34
Oleg Filimonov Avatar answered Oct 13 '22 10:10

Oleg Filimonov