How to auto refreash previous content after press back button form current content android
I developed a android notepad application, I have view interface and edit interface, suppose I edit content in edit interface and press back button to view interface, the view interface's content should be changed from previous one, 开发者_开发知识库at the moment I can't update the view content in the same time, how can I achieve that, please help, thanks! And is there is a way that I can refresh the tab content once I click the tab in tab layout, thanks!
You can start your editing activity by calling startActivityForResult(Intent, int)
. After some editing and pressing back you should pass on exit the result back through setResult()
method like that:
setResult(Activity.RESULT_OK, (new Intent()).putExtra(EXTRA_POJO, p));
In your first activity override onActivityResult(int, int, Intent)
method and get from intent object what you have send.
Remember - if you want to pass objects through intents they must implement Parcelable
interface.
When you press the back button of the "edit interface", you come back to the "view interface".
To refresh the "view interface" you can place your code for updating the content in :
public void onResume() {
super.onResume();
// your updating code
}
The onResmue() is called when the activity comes to the foregroud.
Look at this link for understand the activity lifecycle : http://developer.android.com/reference/android/app/Activity.html
精彩评论