1

我的应用程序上有一个 tabhost,我正在使用一个处理内部 3 个活动的活动组。

示例:ActivityGroup 句柄 A -> B -> C

当我开始这项活动时,我正在使用标志 Intent.FLAG_ACTIVITY_CLEAR_TOP。

我的问题是当用户从 A->B->C 进入并按下后退按钮时,我的 B 活动出现了,但它不会恢复、重新加载或刷新。它具有与以前相同的状态。

例如,如果用户再次转到 C,则 C 会刷新,但当从 C 返回时...... B 不会。

在 BI 上有实现方法,如 onResume、onStart、onReestart 和调试它,主线程永远不会进入那里......

我需要刷新 B,因为 C 可以进行更改以更改 B 上显示的内容。

我已经用谷歌搜索了 3 天,但我找不到解决方案..

4

5 回答 5

2

我也有这个问题。

我正在使用基于此博客文章的ActivityGroup 代码。

当我按下后退按钮时,前一个视图会正常加载,但与之关联的活动不会触发onResume().

我正在使用 on overridden 和 public 的扩展活动onResume()

我找到了这篇博文,因此尝试将视图转换为我的扩展活动并调用onResume().

答对了。

编辑......这里有更多细节......

public class YFIMenuListActivity extends ListActivity {
....
  @Override
  public void onResume() {
    super.onResume();
  }
....
}

onResume()通常受到保护,但我覆盖它并将其公开,以便我的 ActivityGroup 可以调用它。我只在这个活动组中扩展了列表活动(我只是在玩)。如果您有不同的活动,则每个活动都必须覆盖onResume(),我想您必须查看在v.getContext()投射和调用它之前返回的上下文类型。

我的 ActivityGroup 看起来像这样:

public class BrowseGroup extends ActivityGroup {
.....
  @Override
  protected void onResume() {
    super.onResume();
    // call current activity's onResume()
    View v = history.get(history.size()-1);
    YFIMenuListActivity currentActivity = (YFIMenuListActivity)v.getContext();
    currentActivity.onResume();
  }
....
}
于 2011-06-24T18:39:20.233 回答
1

我已经设法实现了 cousin_itt 方法的扩展版本。

在活动组中使用的两个活动中,我将 onResume 从:

protected void onResume()

public void onResume()

然后我在我的 ActivityGroup 中编写了以下 onResume 函数来手动触发 onResume:

@Override
protected void onResume() { 
super.onResume();
View v = history.get(history.size()-1);

MainPeopleView currentActivity = null;   

try {
    currentActivity = (MainPeopleView)v.getContext();
    currentActivity.onResume();
}
catch ( ClassCastException e ) {
    Log.e(TAG, e.toString());
}

ProfileView otherActivity = null;

try {
otherActivity = (ProfileView)v.getContext();
otherActivity.onResume();
}
catch ( ClassCastException e ) {
    Log.e(TAG, e.toString());
}
}

我不得不说,这感觉就像我写过的最糟糕的 android hack。我再也不会使用活动组了。

于 2011-10-13T00:33:40.880 回答
1
((ReportActivity)getLocalActivityManager().getActivity("ReportActivity")).onResume();

ReportActivity 就是你要支持的那个名字 Activity ps: v.getContext();

只返回 ActivityGroup ,不能调用子 Activity onResume

于 2012-03-09T02:54:10.437 回答
0

我发现这onFocusChanged(boolean hasFocus)对于像ActivityGroup. 即使onResume()没有,这也会触发。我将它用于我的一些具有TabHosts 和ActivityGroups 的应用程序。在这里,您可以强制刷新并确保当您Activity重新获得焦点时它总是会被触发。

于 2011-10-13T04:29:29.380 回答
0

我希望你已经用这种方法编写了你的​​刷新数据代码onResume()

于 2011-04-20T10:33:45.163 回答