how do I restart an activity in android? [duplicate]

断了今生、忘了曾经 提交于 2019-11-30 13:39:27
Ted Hopp

This has been posted before:

Intent intent = getIntent();
finish();
startActivity(intent);

As of API level 11, you can also just call an activity's recreate() method. Not only is this cleaner because it is less code, it avoids issues that may arise if your activity was launched by an implicit intent.

Perhaps you could restart the activity as has been demonstrated, but pass in some intent extras to send your string back when it re-starts.

Intent intent = getIntent();
intent.putExtra(STRINGTOSAVE, "Save this string");
finish();
startActivity(intent);

and in your onCreate you would of course want to retrieve the string

Intent intent = getIntent();
String STRINGTOSAVE = intent.getStringExtra(ActivityName.STRINGTOSAVE);

and then use the retrieved string to reapply the textfield and any other actions you need.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!