gpt4 book ai didi

c# - OnResume() 在 Xamarin Droid 中与 TabGroupActivity 一起使用时未在子 Activity 中调用

转载 作者:太空宇宙 更新时间:2023-11-03 15:35:40 24 4
gpt4 key购买 nike

我在 Xamarin 中使用 Tabgroupactivity 来开发一个机器人应用程序。我有一个包含 4 个子 Activity 的 TabGroupActivity。

OnResume() 未在任何子 Activity 中调用。

谁能帮我找到正确的解决方案,为什么它没有被调用!!或者我的代码有什么错误吗?

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)));
}
}
}

设置.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);
}
}
}

最佳答案

使用 OnStart 方法来做到这一点。我们使用此方法在显示 View 时加载/刷新一些 ui 数据。

OnResume:当另一个 Activity 结束时,该 Activity 进入暂停状态。在这种情况下,当用户按下后退按钮时,将调用 onResume

有关 Activity 生命周期的更多信息和很好的解释:See this answer

关于c# - OnResume() 在 Xamarin Droid 中与 TabGroupActivity 一起使用时未在子 Activity 中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31944150/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com