I have a question for Android programming.

Asked 1 years ago, Updated 1 years ago, 100 views

I'm going to make a simple game, and I'm asking you a question because it's hard to get an accurate answer even if I googled.

Create a character class in the game and create an object from character 1 to 9 and have these objects

We're going to play the Go game.

The character class contains information such as the character's physical strength.

But the problem here is that you create a character class and create a separate screen from Character 1 to 9.

The problem is that each character is sprayed on a different screen.

To draw a simple structure,

Main

Character 1 Character 2 Character 3... Character 9

It's configured like this. If you press each character button on the main page, you can see each person's information.

If you press the button on the main in this state, it will proceed to the next day, and if you want to process the object at once, I think it is right to create the object on the main.

Next, we will scratch the information of the object created in the main, spray it on each character's activity, and then show it.

However, there is one big problem.

The main part is made of Fragment, and the problem is that the activity for each character that you receive is activity.

Is there a way to move objects to themselves when moving to Fragment -> Activity? When moving in Intent, I know that it is used when moving from activity to activity...

ex) Character1 = new Character();

in the main (Fragment);

When you create an object like this, you want to use the same information in the activity for each character.

I've been looking for...

We found parceltracer and Singleton.

Do I have to use one of these two methods to do the programming I want?

Or is there another easier way?

I'm sorry for writing rambling because I'm tired and have little programming knowledge, but I'd appreciate it if someone with a lot of knowledge about object movement could answer. ^

^

android object actvitiy

2022-09-22 13:37

1 Answers

Using Intent, data can be delivered not only through activities <->, but also through fragments <-> activities. To deliver objects to the intents, you must implement the Parcelable interface or Serializable.

Please read the article below for more information.

And using the Singleton pattern you mentioned is also a way. Create code to access Character objects from fragments or activities. Please refer to the sample code in the link below for implementation methods.


2022-09-22 13:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.