Android learning summary to obtain the data returned by the started activity

Current activity: contains a button and a textview, which are used to start another activity and display the returned data. Here, onactivityresult() method is overridden.

XML files: activity_ main. xml

The activated activity: contains a button and EditText, which are used to send data back and input the data to be transmitted.

XML files: activity_ another. xml

Operation results:

Add: there is no problem clicking the send back button here to return to the previous activity, but if you click the return key provided by the system, an error will occur. The reason for this bug is that the resultcode is not judged. Click the return key provided by the system, and the resultcode = = result_ Canceled, so it's different.

Solution: so the requestcode and resultcode here can work. In the above program, requestcode = = 0 and resultcode = = 1, that is, it is necessary to judge whether to jump to the activity and return to the previous activity through this button or the system return key. Therefore, the onactivityresult() method in mainactivity can be improved to:

The above is what Xiaobian introduced to you to obtain the data returned by the activated activity. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>