简体   繁体   中英

Using multiple intents to pass information between classes

I am working on a To-Do application. The MainActivity displays the tasks created. When you click Add Task , it takes you to the Create class . Once you set the New Task up, you can click the Save button and it will be passed to the MainActivity via Parcelable .

If you click the newly displayed Task, it takes you to the Display class . From there you can choose to edit the activity, which will take you to Edit class .

Flow of activity:

New Task Creation: Main class --> Create class --> Main class

Editing Existing Task: Main class --> View class --> Edit Class --> Main class

QUESTION : If you are in Edit , how do you send back the information to update it in the MainActivity?

From the MainActivity I was using startActivityForResult() . Would I do a compounded startActivityForResult()?

Example:

Main class calls startAFR --> View class calls start AFR --> Edit --> Edit returns info to View --> View returns info to Main

您可以在实用程序类中使用静态字段。

The way I solved this problem was to use Intents and send the data back to the necessary activities. Similar to the MainActivity , I used startActivityForResult() to get the information I needed and passed it between the necessary classes. By using return codes in the Overridden onActivityResult method, I was able to perform whatever actions I needed. I'm not sure if this was the proper way to handle this but from my little knowledge of Android it's all I could generate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM