0
\$\begingroup\$

I'm a student who is just stepping into android game development.

I'd like to create a text-based RPG game for android and started to learn about Android Studio (I think Android Studio is enough because I'm not using any 2D or 3D sprites).

But then I got into some confusions about the activity.

I learned that an activity has a life cycle from onCreate to onDestroy.

In some tutorials, I heard that activities are just various scenes that can be used within an app.

With that said, my question is, can an activity be used for a game scene?

For instance, I'm thinking about creating game scenes like the battle scene, exploring scene, town scene, inventory scene etc.

But opening up another scene, or activity, would destroy the previous one in which, in some cases, I would not want that to happen. (Am I correct on this?)

Do I need something else other than activity to create those scenes?

\$\endgroup\$
1
\$\begingroup\$

Every activity is an individual application screen, so you are correct in thinking they could be used for, as you put it, individual game scenes.

The activity lifecycle is set up the way it is to facilitate memory management. Most Android devices have a small amount of RAM available (1 or 2 GB), which is often shared between the OS and several other applications. To put it simply, if applications were able to hold onto their activities for however long they want, the device would very quickly run out of memory. This leads to lag, hanging, and crashes.

To pass data between activities you can use intents. The "Building Your First App" section of the Android Developers website, for example, shows how to pass a message from one activity to be displayed in another activity. If you need something more robust, Android offers plenty of different storage options.

You can also use fragments to create different contexts within the same activtiy. For example, opening a stat page during battle.

Udacity has several great, free online courses on Android development. These can teach you the basics and technicalities of the Android platform, and much more if you're feeling curious. Of course, the official Android API guides are always a good reference to look into.

In summary, your question is too general to warrant a particular answer. Yes, it is possible to do what you want to do. How one would go about doing it, however, depends on a lot of factors. Hopefully you now have an idea of where and how to start experimenting. Good luck!

\$\endgroup\$
0
\$\begingroup\$

You could use the xml layout fIle to play out different scenes within an activity. For example you can make a text visible and invisible when certain actions have been done ( press a button/timer etc.). This way you don't need an activity for every scene. Hope I helped you on your way a bit.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.