简体   繁体   中英

Android - Efficiency + Multiple Activities & Storing Data

I've been out of the game for awhile with coding and decided to refresh myself with some Android stuff. I'm trying to make a pretty basic app with radio buttons and text on many pages and people follow their own route in a story.

Problem starting off is this could end up having hundrends / thousands of activities. Is there a cleaner or more efficient way of doing this?

Second problem I'm wondering is what's the best way to store the player's statistics - eg health etc so that they're available after shutdown (I recall I should use onStop() or something similar?)

Cheers for any tips! Ken

Number of activities is not a problem. The OS will destroy activities in the stack. When the user navigates back, it will recreate the activity with the original intent and anything you saved in onSaveInstanceState (so you'll probably have to use that).

With data storage. you have sqlite + contentprovider or you can go straight key value with SharedPreferences.

Having a bunch of Activities seems a bit excessive. Why not just one Activity and load text for the story and radio buttons from string resources as needed?

SharedPreferences would probably be the simplest storage method to get up and running.

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