0

I am calling one activity on click of status bar notification which is having a Complete button. on click of btn. i have folllowing code -

public void completeTask(){
        taskDBAdapter.deleteReminder(rowId);
        taskDBAdapter.close();
        Intent intent = new Intent(this, TaskManagerActivity.class);
        startActivity(intent);
        finish();

    }

whhen i click complete btn new activity (TaskManagerActivity) gets opened properly.But if i reopen my application it still tries to open this activity and not my default landing activity. Any help on this.??

EDIT -

I have tried repositioning my finish() statement . Still its not working.

EDIT 1.1 - Ok I will provide some details here. Assume my app has two activities

  1. Main Activity
  2. Notification Activity

My app create some notification to display on Status bar. So as soon as i click on status bar Notification actvty will open. Now there is a button called Complete on click of which the code given will fire and main activity (in the code TaskManagerActivity.class) will open. But after I press back button in my app and again reopen it , it opens the notification activity when it should have fired the main activity (as it is launching activity).

Thanks, Ray

RayKaushik
  • 301
  • 5
  • 17

2 Answers2

2

That's the default way android functions. If you press the home button and then open your app again, it will restore the apps previous state (unless it has killed the apps processes and activities due to memory constraints). So you are not actually restarting your app but only restoring it.

If you wanna quit the app, then press the back button. Now when you re-open the app, the original activity will be launched.

Do not modify this behavior. It is the default system behavior and users expect it to work this way. Your app is fine :-)

Anup Cowkur
  • 20,443
  • 6
  • 51
  • 84
  • i have added some details.Can you please have a look and let me know if you understand the issue / need more input. – RayKaushik Nov 18 '12 at 15:54
0

- First of all the behavior which you are experiencing is the way Android is made to function, moreover when a user gets a call while this app is open, after finishing the app he will definitely want to get back to the state where he left the application.

Still if you want it that way, here it is.....

- Make sure your application has only single instance of it running, by using android:launchMode="singleTask", or android:launchMode="singleInstance"

- Then finish() your Activity at onPause().

@Override
void onPause()
    {
    super.onPause();
    finish();
    }
Kumar Vivek Mitra
  • 33,294
  • 6
  • 48
  • 75
  • i have added some details.Can you please have a look and let me know if you understand the issue / need more input. – RayKaushik Nov 18 '12 at 15:54