Adding libgdx to an Android Native Application - java

I have a simple kids app which teaches things such as colors, numbers, etc... which I am currently developing. It uses what I would consider "standard android java programming (Single Xml/java class)." I also have a simple game with a Dinosaur that jumps over letters using libgdx.
My question is, I would like to have the game as part of the "overall" app. I would like to know if it is even possible to add a libgdx game to an android native application. I tried adding the appropriate files to my app, but this caused a compile error, could someone point me to a place where I could find help on this issue, or perhaps let me know if what I am wanting to do is even possible? Thanks.
---To clairify, my main app has a menu which takes you to activities. I would like the libgdx game to be one of the activities.
---Edit to response---I compile using Gradle and have more errors than I can count. I've since removed the libgdx game from the app so I am not sure of specific errors, but iirc there were over 100, many of which were R issues, which I could have figured out, but I couldn't find anything on either S.O. or the web saying it was even possible to add libgdx to a non-libgdx app.

You can integrate your App with your libgdx game.
AndroidLauncher.java is your libgdx Activity and you can move from one activity to another using Intent.
intent = new Intent(this, AndroidLauncher.class);
startActivity(intent);
and movement from libgdx AndroidLauncher.java, you need to call it from inside the core project classes. You need to use an interface.
https://github.com/libgdx/libgdx/wiki/Interfacing-with-platform-specific-code
If your game is sub view of your App.The AndroidApplication class (which extends activity) has a method named initializeForView(ApplicationListener, AndroidApplicationConfiguration) that will return a View you can add to your layout.
Pros.-Code is already you have,only you need to integrate.
Cons.-you need to maintain OpenGL Context Loss. Libgdx do for you.

In Libgdx your entire game is just a single Activity. You can start it as any other activity from your code.
Please follow Can I run an Activity before running libgdx? for details.

Related

Uninterrupted background music across all activities in Android Studio game

I am currently working on a game in Android Studio and am having issues with implementing a constant soundtrack across all activities. The way I want it to work is that when the app is started up, an audio file will begin playing and looping and will continue looping throughout all activities, and essentially never end (or restarted when changing activities). At some point I would also add a mute/silent button as well. My question really is, how can I create a class for this sound file to play on repeat upon booting the app and also continue without interruption when changing activities. As it currently stands I have a few lines declaring a Mediaplayer object and setting it to loop and playing it, within each activity.. I realize this is not an efficient implementation but I am brand new to Android Studio and still figuring this out.
Follow this tutorial:
https://www.codeproject.com/Articles/258176/Adding-Background-Music-to-Android-App
And start the Music Service in your MainActivity, if there are still any issues, then let me know.

Is it possible to create an App Widget from within an App in Android?

Is it at all possible to create an App Widget programmatically from within an Android app itself? I'm rather lost on how to do this and Googling so far has led me to believe that it is not possible (that an App Widget and an App itself has to be separate applications).
So, would it be possible to dynamically create an App Widget from within an Android App? If not possible, how would you approach it? Thanks all!
Is it at all possible to create an App Widget programmatically from within an Android app itself?
That would depend completely upon what you mean by this.
I'm rather lost on how to do this and Googling so far has led me to believe that it is not possible (that an App Widget and an App itself has to be separate applications).
No, an app widget most certainly can go in the same Android project as the rest of the application. In fact, usually it does.
So, would it be possible to dynamically create an App Widget from within an Android App?
Again, you seem to think that the world knows what you mean by "dynamically", forcing us to guess.
An app widget, from the standpoint of code, consists of an AppWidgetProvider, an entry in the manifest pointing to that AppWidgetProvider, a metadata XML file, and whatever other resources you need (layouts, drawables, etc). All of that has to be written by a programmer and included in the app at compile time -- you cannot "dynamically" create those things.
An instance of an app widget is put on the home screen by the user, not by the programmer. Hence, a programmer cannot "dynamically" create instances of an app widget.
What the programmer can do "dynamically" is decide what is displayed inside of the app widget (e.g., current headlines for a news ticker, current song being played for a music player).

Developing a Java app that runs both on the web and as an Android app?

I'm working on a game which would work both on the web, as an applet, and on the Android phone, as an app.
Is that possible to do, and if so, what do I need to be aware of to make that work (i.e if there are any settings that I shouldn't hard code and instead determine them based on the user's device when the game is run, or any java libraries that I shouldn't use?).
Also, the game needs to accept touchscreen as input for the Android app. Is that possible to build into the same game which will also be run as an applet? May be so at run time, the applet decides whether to use Mouse or Touchscreen for the input when it is run?
Although Android apps are written in Java, the framework around the app is extremely different of the framework wrapped around an applet. You won't be able to have one .jar file that you can include as an applet and throw at an Android device because that's just not how it works.
You will however probably be able to create all the game logic and objects and have them in be shared with the applet code and android app. You can probably even get away with having them in one repository and project (although it's probably going to have to be an Android project that you then wedge in your app build scripts).
In order to tackle the different controls for your game you are probably going to have to abstract away the input, and have your game/level object have a call back like userHasPoked(int x, int y) and then have the applet call that method on click of the mouse and the android app calls it on touch (which is oddly still called onClick).
I think it'll be a long road, but much easier than rewriting the whole thing. It'll probably seem like a lot more work up front, but once you are done wedging your code into an applet and an Android app, you'll probably "never" have to touch that code again and can just keep adding to the game.
I wouldn't underestimate the task, but that sounds like a very fun programming exercise. Good luck!
What kind of game do you develop? It may be the better approach to develop an Javascript game.
That can be installed with phonegap (cordova) onto an android device.
Let me break this for you....
Model - The Business Logic and Data
View - The Display of the Output of the Model
Controller - On which the action is done.
The advantage of using this MVC architecture is that, you can keep the same model and keep changing the Views.
So keeping this idea in mind, you can have the same model for both the Web App and the Android App, and then implement each others Views to it respectively.

Integrating multimedia with LibGDX

According to the LibGDX web page:
Android applications can have multiple activities. Libgdx games should usually only consist of a single activity. Different screens of the game are implemented within libgdx, not as separate activities. The reason for this is that creating a new Activity also implies creating a new OpenGL context, which is time consuming and also means that all graphical resources have to be reloaded.
However, this isn't impossible to do - just undesirable.
I'm building an app that is designed to hold a few games built in LibGDX, as well as some information alongside it - video/audio, text with illustrations, and so on, describing the development of the games.
Is it a better idea to build this as a native android application that launches and tears down LibGDX whenever the user wants to play a game? Or should I write the entire app through LibGDX and do try and do the non-game stuff using UI libraries and so on?
I'm sorry I can't nail this down to a more specific question. I'm really interested to know before I embark down the wrong road.
The consensus in a linked Reddit thread here is that setting up and tearing down a LibGDX activity isn't such a huge overhead, particularly if the games are small (which they are in my case).
I'm going to opt for this solution, and simply shut down the activity whenever the user stops playing a game.

First android app for iOS developer

i am iOS app developer. Now when i created an app on iOS i want to do the same on android. With java i was familiar just now need some time to remember.
i was looking at some tutorial how to do one or other things. But what i can't find is the basics how everything works. How classes is interacting with each other.
For example i want to create registration window with few buttons and alerts.
I want registration window to be called just once when app is installed and just that.
Should i create new java class and few layouts, one for View with buttons and other for Alerts ?
Or should i create other class for alerts if i need them in other flow of my app ?
And how i should call that window with registration from my main class, which is
extends Activity
Also if there are some developers who came this road from objective-c (iOS) to java (android). It would be nice for some share experience how they did that.
Thank you for any help :)
Very few of the concepts in iOS and Android are similar. On Android you have Activites, Intendts the Manifest. When you design your layout it should be resolution independent. You have a search, back and a menu button and variable hardware. All of this has no equivalent in iOS.
That said, I think you just have to read the basic concepts and the getting started guide no matter if you come from iOS or never have done mobile development before.
EDIT
To answer your concrete question. Take a look at the lifecycle of an Activity and Preferences. With this, you could do some action on the first start of your main Activity and store some flag in the preferences when it's done. On the next start you just test that preference and skip the logic.
You can create one activity (.java file) and one layout(.xml file with buttons and input boxes) , alerts could be toast notifications:
http://developer.android.com/guide/topics/ui/notifiers/toasts.html
All you require for this is a activity and a layout xml for that activity, this activity will be your main ie the entry point to your application, in that activity oncreate method you can check if it is registered or not by setting a flag or something which will direct to the next activity if its registered.
GOOD LUCK...
Just like your nibs in iPhone you create xml layouts in Android. And for view controllers here you make activity. One important thing is AndroidManifest.xml file, it contains all information of your app (like plist) plus all the activity information(Intent type and launcher methods).

Categories