0

I have need to show autorizationa activity if user not autorized.

I have use Launcher activity (has nohistory flag) with next code:

protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);

    if (Autorization.isAutorized()) 
    {
        Intent newIntent = new Intent(this, MainActivity.class);
        // add some flags????
        startActivity(newIntent);
    }
    else startActivity(new Intent(this, AutorizationActivity.class));
}

When autorization are complete, AutorizationActivity starts Launcher with FLAG_ACTIVITY_CLEAR_TOP and then Launcher starts MainActivity, but I have some trubles with backstack. By pressing back in MainActivity android shows AutorizationActivity again instead to hide task.

What flags I must use to prevent go back to AutorizationActivity from MainActivity?

Shruti
  • 1
  • 13
  • 55
  • 95
Nik
  • 7,114
  • 8
  • 51
  • 75
  • I have remove no history flag and add finish(); after start MainActivity methods. It is correct way? – Nik Apr 17 '12 at 06:13
  • may or may not work.. setting flag is the reliable way.. – ngesh Apr 17 '12 at 06:17
  • It is work! Also I have add in AutorizationActivity next code: public void onBackPressed() { moveTaskToBack(true); } – Nik Apr 17 '12 at 06:25

2 Answers2

1

There are several ways to do this , the easiest would be to use the AndroidManifest.xml file. Just add android:noHistory = "true" in the authorization activty.

Also have a look at the following question : removing an activity from the history stack

Community
  • 1
  • 1
Tejas Kale
  • 415
  • 8
  • 18
  • I can not add this flag to autorizationactivity i.e. it is not one activity, user must have ability go back in avtorization process – Nik Apr 17 '12 at 06:18
  • @Nik .. you might want to try http://stackoverflow.com/questions/9937120/switching-between-activities-in-android/9937281#9937281 – ngesh Apr 17 '12 at 06:22
0

try setting flags for AuthorizationActivity in Manifest something like this.... right now your flag applies only to MainActivity and not the Current Activity.. so set in Manifest instead..

ngesh
  • 13,398
  • 4
  • 44
  • 60