0

I have a service that turn on my app sometimes, the main activity prompt Dialog message to user sometimes, after the user answer YES\NO I call to finish() to close the app.

my problem is when the message is shown, user answers it and app was call to finish() and when you look in the recent history you played before (in samsung for example you press long on home button) you will see my app along with other apps user started.

when you push it to open it again the Dialog show again..

How to show the activity when launched from recent app without showing the Dialog

public void dialog_1(){
        myDialogViewN = new MyDialogViewNegativeTime(MainActivity.this);

        // Setting vibrator
        vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        long[] pattern= {100, 1000};
        vibrator.vibrate(  pattern,0   );

        // Setting 2 Dialog Listeners       
        myDialogViewN.setOnDialogListener(new DialogListener()      {           
            @Override
            public void onNegativeClick()
            {           
                // Stopping Vibraror
                if (vibrator.hasVibrator()){
                    vibrator.cancel();
                    vibrator = null;
                }

                initialize_DialogToUser();                  /// ??
                SendDataToService(3);       //doesn't want reminder
                myDialogViewN.dismissDialog();
                waitForDialogAnswer=false;
                finish();
            }

            @Override
            public void onPositiveClick()
            {
                // Stopping Vibrator
                if (vibrator.hasVibrator()){
                    vibrator.cancel();
                    vibrator = null;
                }

                initialize_DialogToUser();
                SendDataToService(1);       //remind!
                myDialogViewN.dismissDialog();

                squre.setImageResource(R.drawable.triangle_red2);
                waitForDialogAnswer=false;
                finish();
            }       });         
     myDialogViewN.show();
    }
@Override
public void onDestroy()
{
    super.onDestroy();

    // close/stop running application on background
    int id= android.os.Process.myPid();
    android.os.Process.killProcess(id);
}
ofir_aghai
  • 3,017
  • 1
  • 37
  • 43
  • Do a debug and see: 1- if the "myDialogViewN.dismissDialog()" hide your dialog 2- That the myDialogViewN.show() is not called again on resume the activity – Sulfkain Sep 16 '13 at 09:56
  • i was chacked it,the dialog is clearly disapear after user answer (by `myDialogViewN.dismissDialog()`), but the problem is still. every time i open the app from history-app, the dialog is show again – ofir_aghai Sep 16 '13 at 11:21
  • it seems that android save this app state *just* if you open it from history. but if you open it generaly by click the icon, it's ok at this openning.. – ofir_aghai Sep 16 '13 at 11:23
  • Ok, you checked the dialogs hides, but the other i told you? I have used dialogs many times and this never happens. – Sulfkain Sep 16 '13 at 11:37
  • i chacked the `myDialogViewN.show()` too, and it realy call again. – ofir_aghai Sep 16 '13 at 13:56
  • There you have, follow the call to dialog_1() after stop (finish) your app and see where and why is calling again if don't have to be – Sulfkain Sep 16 '13 at 13:58
  • i chacked the `myDialogViewN.show()` too, and it realy call again. after a search i see that it's different to open your app from history and from the main icon, if you open from history the intent of this activity was not delete! there is a way to chack it by a flag of intent - `Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY` [link]http://stackoverflow.com/questions/8733634/flag-activity-launched-from-history-isnt-set-for-intents-from-history[link] [link]http://stackoverflow.com/questions/4866149/android-starting-app-from-recent-applications-starts-it-with-the-last-set-of[link] – ofir_aghai Sep 16 '13 at 14:05
  • but it's still not work, i didnt success to use this flag , because the flag is everytime != 0 so i still dont know if open from history or not – ofir_aghai Sep 16 '13 at 14:29

1 Answers1

0

finally i find solution, the problem was when you open the app from history - the last intent that comes from service to your activity stay there and not goes, in contrary for openning the app by click it's own icon. (different openning ways).

my solution:

send 2 intent's from service to activity,

the first - with what you really need.

the second - after you receive your answer in the service. in the second you will not put any data! it is a mere intent that comes to change the "stuck" intent in history-app open way.

maby it is stupid, but it's the only solution i found :)

ofir_aghai
  • 3,017
  • 1
  • 37
  • 43