以编程方式重新启动/重新创建活动?

编程入门 行业动态 更新时间:2024-10-25 19:20:56
本文介绍了以编程方式重新启动/重新创建活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我做我的数据库中的一些变化,这涉及到我的观点显著的变化,我想重绘,重新执行的onCreate。

After I do some change in my database, that involves significant change in my views, I would like to redraw, re-execute onCreate.

这怎么可能?

推荐答案

嗯,也许这是不是做的事情(根据CommonsWare的评论)的一个很好的方式,但我处理这种情况在我的比赛方式是简单地重复使用启动该​​活动的意图。定义一个意图 starterIntent 在类的顶部,并在onCreate方法使用 starterIntent = getIntent()检索意图开始了这项活动。然后,当你要重新启动该活动,请拨打结束(); startActivity(starterIntent);

Hmm, maybe this isn't a good way of doing things (according to CommonsWare's comment), but the way I've handled that situation in my game is simply reusing the intent that started the activity. Define an intent starterIntent at the top of your class and in the onCreate method use starterIntent = getIntent() to retrieve the Intent that started this activity. Then when you want to restart the activity, call finish(); startActivity(starterIntent);

就像我上面写的,也许这并不是一个很优雅的解决方案和废物的处理时间,但它是一个简单的方法来重新启动活动,并迫使它重新加载一切。

Like I wrote above, perhaps this isn't a very elegant solution and wastes processing time, but it's a simple way to restart your activity and force it to reload everything.

更多推荐

以编程方式重新启动/重新创建活动?

本文发布于:2023-11-04 01:13:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556551.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:创建活动   重新启动   方式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!