Numerous Activities in an app - android

I just started learning Android App Development recently and I'm curious about this;
Suppose I want to make an app with lots of activities(pages) for example a Bible app with around 1189 chapters with Each chapters having different activities. Does that Mean I will create about 1189 different activities or is there an easier way to create this type of app?

You can use a lot of design patterns. You can put the information you want to display in an class. Then you could span 1189 objects. You could create just one activity, and get 1189 different objects' information. Finally display in activity.
like this https://github.com/newcaoguo/booksource/tree/master/chapter3/RecyclerViewTest

Related

Can I use single input form to collect data from multiple Activities in Android Studio?

So hello everyone! Greetings for the day!
There are serveral Activities in Android studio I have to get data with. Total of 6 data inputs. However one user enters data for only one of them.
Here's the design sketch.
https://ibb.co/X5yyzQM
So do I have to design 6 Activities with input forms like this or is there any method to use one input form to use for 6 activities and get data with unique form value to the database?
Like BanquetStarter(name, address..) , BanquetBronze(name, address..) etc.
Appreciate your kind help. Appologies for your valuable time.
Thanks ❤.
These are separate screens, but do not necessarily have to be separate activities. Consider architecting this with Fragments. This would allow you to utilize a single ViewModel bound to the lifecycle of the Activity. Each fragment would be responsible for collecting its own information and handing that into the ViewModel, and then once all the information is submitted, you have it all in one place and ready to go.
Activities are heavy weight components, whereas Fragments are lighter weight. Unless you have a very good, explicit reason to do so, prefer a single activity approach with multiple fragments (or multiple composable screens, if this app is being written from scratch utilizing Jetpack Compose).

Android application architecture - fragments

Given the fact that I don't have very extensive experience when it comes to Android apps, I have a questions regarding the architecture of an application :
Are there any problems I can run into if I decide to create an application that has only one activity and I 'load' all the other content using fragments only ?
Thanks
No, this approach is absolutely all right. More than that, Fragments are more lightweight then Activities, so you can gain performance by using this approach. However, keep in mind, that Activity is designed to behave as a single user screen that serves for a concrete purpose, and Fragments are the parts of this screen. So your approach works well if the whole application should contain a single user screen according to the design, thus serving for a single concrete and properly defined purpose.

Should I separate single and multiplayer game modes into different Android activities?

I've been developing a turn-based game, which has both single player and (local) multiplayer options. The gameplay is largely similar between the two apart from the fact that CPU controls one of the turns in single player.
Is it wise to make a separate Android activity for both options or make one activity which handles both via booleans etc?
What you should do is have a library or helper classes that contain the ground for both activities and then have the two different activities (One for single and one for multiplayer) this way you don't need to duplicate the code and its only there once. Also with this its easier to fix if something goes wrong.
For debugging you should have different log tags for each activity and put try things around all the things that need it and log the errors with their log tags.
According to oracle you should keep your java files under 2000 lines of code as well, so if it goes over this definitely split them up.

Android Share User ID between two apps

I have two games one is paid and other one is FREE. I have added many themes in my paid app.
I want to incorporate all the new things into my free game and sell things one by one, they both have different package name.
Is there any other way around like sharing user id between two apps rather than copy pasting code base of one to another?
I have developed both games in AndEngine.
You probably want to learn a bit about android Intents. They one way you could share data between the two apps.
http://developer.android.com/training/sharing/send.html
If all you are passing is a simple bit of text it should be easy.
Another approach is using SharedPreferences, discussed in this Stack thread:
The easiest way to pass data between application in Android
Although the poster seems confident, I am not sure that another app can listen to the SharedPreferences of another app. And if you could it could constitute a serious security risk unless there is some way to assure that ONLY your apps can share that data.

Android project architecture: database and map?

My project is a visitor app for a University, that basically displays places and events on a map, and allows the users to interact with one another by making posts with advice/recommendations/questions and so on.
So far I've been trying out bits of code seperately (lists, tabs, the basics), following the android tutorials and trying things for myself. My problem is that I'm not sure how to combine all the bits of code into one project.
I know that I need to make a database, and a map (using OSM rather than google).
The database will store information on places, events, and posts that users have made. With co-ordinate information because they need to go on the map. This information is also displayed in seperate tabs - e.g. a list of places.
My problem is that I don't know how this will all fit together.
Will I need seperate classes for the database, populating the lists, and displaying on the map? Or can they all be in a single class?
I'm a little hazy on how the classes and activities are going to communicate, too. At the moment I'm thinking the database object is going to get passed to the listviews and mapview, which then take and display some of the information?
Any advice on how to cobble these elements together would be much appreciated. :D
I think I will need to subclass SQLiteOpenHelper for my database, so it'll need to be its own class?
I'm thinking of using OSMdroid for the map, which I'm not sure how to do yet.
And everything needs to be inside a tabview.
Welcome to StackOverflow!
Your question is very vague and broad, and likely to get closed as "not a real question" - I suggest you take problems one by one and ask specific questions as you go along and run into problems. Try to think about your problem in these terms: what's the minimal thing I need to get it to do the thing I want. Keep in mind that ANYTHING you want to do is possible, the main question to ask yourself is: what do you want your application to do exactly? Think about the number of different screens (activities), and how they would communicate to each other (when you click XXX, that will lead you to YYY, and so on). One advice: start simple, it's very easy to get buried in too much complexity, especially since it's your first project. It can quickly become very complex, even with a simple concept.
As you didn't specify your level of expertise in coding, it's difficult to give precise advices: but coding an android application is not very different from a "regular" application, with a web or Swing or C# user interface. So I would advise you to learn about OO programming in general, things like composition, inheritance, encapsulation, dependency injection, unit-testing, etc.
Then start writing a base Activity for your main view, write its layout, and add views and graphical elements to it. Then add the listener code for your widgets, that will generate Intents to other Activity.
Then add a DatabaseHelper when you want to save stuff in a database (that can come later, to begin with, you can just "stub" the interactions to a database, by writing what you would save to db on screen using Toast for example).
All objects can be injected into other objects by passing a reference to them, either at construction time or through setters.
Sorry not to be more precise, as I said it's a very vague question.

Categories

Resources