以编程方式重新启动/重新创建活动? [英] Programmatically relaunch/recreate an activity?

查看:92
本文介绍了以编程方式重新启动/重新创建活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我做我的数据库中的一些变化,这涉及到我的观点显著的变化,我想重绘,重新执行的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.

这篇关于以编程方式重新启动/重新创建活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆