2

I am using Tabgroupactivity in Xamarin to develop a droid app. I have a TabGroupActivity with 4 child activities.

The OnResume() is not being called in any of the child activities.

Can Anyone please help me with the right solution why is it not being called!! or Is there any fault in my code?

TabGroupActivity.cs

namespace RB.Droid
{
[Activity (Label = "TabGroupActivity")]         
public class TabGroupActivity : ActivityGroup
{


    private List<string> _idList;

    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);

        if (_idList == null)
            _idList = new List<string> ();



    }


    public void StartChildActivity (string id, Intent intent)
    {
        intent.AddFlags (ActivityFlags.ClearTop);

        var manager = new LocalActivityManager (this, false);

        var window = MainTabActivity.localActivityManager.StartActivity (id, intent);
        if (window != null) {
            _idList.Add (id);
            SetContentView (window.DecorView);
        }
    }

    public override void FinishActivityFromChild (Activity child, int requestCode)
    {
        var manager = new LocalActivityManager (this, false);
        var index = _idList.Count - 1;

        if (index < 1) {
            Finish ();
            return;
        }

        MainTabActivity.localActivityManager.DestroyActivity (_idList [index], true);
        _idList.RemoveAt (index);
        index--;
        var lastId = _idList [index];
        var lastIntent = MainTabActivity.localActivityManager.GetActivity (lastId).Intent;
        var newWindow = MainTabActivity.localActivityManager.StartActivity (lastId, lastIntent);
        SetContentView (newWindow.DecorView);     
    }

    public override bool OnKeyDown (Keycode keyCode, KeyEvent e)
    {
        if (keyCode == Keycode.Back) {
            return true;
        }
        return base.OnKeyDown (keyCode, e);
    }

    public override bool OnKeyUp (Keycode keyCode, KeyEvent e)
    {
        if (keyCode == Keycode.Back) {
            OnBackPressed ();
            return true;
        }
        return base.OnKeyUp (keyCode, e);
    }

    public override void OnBackPressed ()
    {
        var length = _idList.Count;
        if (length > 1) {
            var manager = new LocalActivityManager (this, false);

            var current = MainTabActivity.localActivityManager.GetActivity (_idList [length - 1]);
            FinishActivityFromChild (current, 0);
        }
    }


}
}

SettingsActivityGroup.cs

namespace RB.Droid
{

[Activity (Label = "SettingsActivityGroup")]            
public class SettingsActivityGroup : TabGroupActivity
{
    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);

        // Create your application here
        StartChildActivity ("Settings", new Intent (this, typeof(Settings)));
    }
}
}

Settings.cs

namespace RB.Droid
{

[Activity (Label = "Settings")]         
public class Settings : Activity
{
    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);

        // Create your application here
        TextView tv = new TextView (this);
        tv.Text = "Settings";
        SetContentView (tv);
    }

    protected override void OnResume ()
    {
        base.OnResume ();

        Toast.MakeText (this, "ON RESUME NOT CALLED", ToastLength.Long);
    }
}
}
Ravitheja
  • 761
  • 1
  • 8
  • 24
  • Please describe what you are doing, when you want the OnResume Method to be raised (info about the method: http://developer.android.com/reference/android/app/Activity.html#onResume()) – Joehl Aug 11 '15 at 14:27
  • @Joehl: I want to call a method where a user should be checked for his login whenever he comes to the screen. SO i want to call the method in onResume(). It works in android but to my bad, Its not working with xamarin . – Ravitheja Aug 11 '15 at 15:11

1 Answers1

0

Use the OnStart Method to do that. We use the this method to load/refresh some ui-data when the view gets displayed.

OnResume: The activity goes in Pause state when another activity comes over it. In this case when user pressed back button then onResume get's called.

More infos and good explanation to activity lifecycle: See this answer

Community
  • 1
  • 1
Joehl
  • 3,671
  • 3
  • 25
  • 53
  • yeah, but if you are interchanging between the tabs, OnStart() will not be called. so i need to call that method even upon shifting between the tabs. – Ravitheja Aug 12 '15 at 09:48