Question

Java answers fine, I tend to use C# for Android.

In my ActivityGroup I have this method which starts and shows a child activity:

    public void StartChildActivity (string Id, Intent intent)
    {
        intent.AddFlags (ActivityFlags.ClearTop);
        Window window = LocalActivityManager.StartActivity (Id, intent);
        if (window != null)
        {
            mIdList.Add (Id);
            SetContentView (window.DecorView);
        }
    }

However, when I handle the back button to "pop" off a view and return it to the previous one, the app closes when finish is called:

    public override void OnBackPressed ()
    {
        int length = mIdList.Count;
        if (length > 1)
        {

            Activity current = LocalActivityManager.GetActivity (mIdList [length - 1]);
            current.Finish();
        }           
    }

How do I get the view to "pop" instead of shut down the app?

Was it helpful?

Solution

This sounds very familiar trying to make an iOS port?

This is how I start my activities

 String id = "SOME_UNIQUE_ID";
 Intent intent = new Intent(context,SomeClass.class);
 intent.putExtra("UniqueID", id);
 LocalActivityManager m = getLocalActivityManager();
 Window w = m.startActivity(id, intent);
 setContentView(w.getDecorView());
 intentStack.push(intent);

This is how i finish my activities on back

 LocalActivityManager m = getLocalActivityManager();
 Intent i = intentStack.pop();
 m.destroyActivity(i.getStringExtra("UniqueID"),true);

the intentStack is just where i keep the intent stack so i can find those activities again.

That should be what you need but regardless you should re-evaluate your need to use TabActivity/ActivityGroup as that class and all subclasses has been deprecated as of 2.2 or 2.3. You should consider moving to fragments and using the support library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top