Android 活动更新

发布于 2024-10-10 01:28:22 字数 783 浏览 4 评论 0原文

我正在从其内部调用一个活动 - 基本上我有一个新故事列表和两个过滤按钮,当单击这些按钮时,会重新启动该活动,并传递改变新闻故事的意图。

当我运行应用程序时,它可以工作,但有一秒钟我得到了旧的活动 UI,而应用程序从新的 xml 源读取,然后 UI 更新。有什么方法可以阻止这种情况发生并让活动重新启动冷状态。

这是我当前附加到 onclicklistener 的代码,

public void openFootballNews(View v) {
 Intent i = new Intent(this, News_Landing.class); // News_landing class is the class this code is in
 Bundle bundle = new Bundle();
     bundle.putString("code", "football"); // this, if set, changes the xml feed to read
     i.putExtras(bundle);
     i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
     this.onCreate(null); //this has halved the time the old UI is on the screen for but I cant get rid of it completely
     startActivity(i);
}

任何帮助都会很棒,谢谢!

I am calling an activity from within itself - basically i've a list of new storys and two filter buttons that when clicked restart the activity with an intent passed that changes the news stories.

When i run the app it works, but for a second i get the old activity UI while the app reads from the new xml feed and then the UI updates. Is there any way to stop this from happening and get the activity to restart cold.

here's the code I am currently attaching to the onclicklistener

public void openFootballNews(View v) {
 Intent i = new Intent(this, News_Landing.class); // News_landing class is the class this code is in
 Bundle bundle = new Bundle();
     bundle.putString("code", "football"); // this, if set, changes the xml feed to read
     i.putExtras(bundle);
     i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
     this.onCreate(null); //this has halved the time the old UI is on the screen for but I cant get rid of it completely
     startActivity(i);
}

any help would be great, thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离鸿 2024-10-17 01:28:22

从活动本身开始没有多大意义(除非您的目标是做一些深奥的递归事情;))。另外,我可能是错的,但我相信活动是保存在堆栈中的,这样当您在新闻报道之间切换时,您就会将一个又一个几乎相同的活动堆积起来。我同样认为手动调用 onCreate() 是一种不好的形式。

需要查看您的所有代码,但我的猜测是您正在阅读您的提要并在 onCreate() 中创建列表,并且您最好的选择是将其重构为 openNews (String sport) 方法,您可以在 onCreate() 中调用一次该方法,并在侦听器中再次调用该方法。

Starting an activity from itself doesn't make much sense (unless your aim is to do something esoterically recursive ;) ). Also, I may be mistaken, but I believe activities are kept in a stack so that as you flip between news stories, you're piling up one nearly-identical activity after another. I'd similarly think calling onCreate() by hand is bad form.

Would need to see all of your code, but my guess is that you are reading your feed and creating your list inside onCreate(), and that your best bet is to refactor that into a openNews(String sport) method, which you call once in onCreate() and again in your listener(s).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文