I'm currently developing a game app for my 2nd year project at uni, but i'm a little stuck on how i can move from a non-activity class to an activity. So my none activity class is a quit screen within the game (yes i know you shouldn't use quit in a game but its one of my requirements), when i click on a button i want it to take me to the activity. (which basically thanks the user for playing and then exits the app) using System.exit(0) is just going back to the last activity visited.
The screen extends my Game Screen Class which is a parent class i created, this is the code for what happens when the user touches the 'yes' button in the quit screen:
#Override
public void update(ElapsedTime elapsedTime) {
Input input = game.getInput();
List<GameTouchEvent> touchEvents = input.getTouchEvents();
if(touchEvents.size() > 0){
GameTouchEvent touchEvent = touchEvents.get(0);
if(yesButtonBound.contains((int) touchEvent.x, (int) touchEvent.y)){
System.exit(0);
}
I'm not looking for specific code answers as this is a project but any advice or hints would be very appreciated thanks!!
Related
I created a libgdx game that works fine on desktop mode, then I tried it to run on android platform. The game goes to the menu screen without any problem but when I click the play button, the game closes "Unfortunately, mygame stopped working".
I have a loding screen and when it's done loading the assets it goes to the menu screen:
if(assetManager.update()){
game.setScreen(new MenuScreen(game, assetManager));
}
Then on my menu screen I have a play button that when clicked it goes to the game screen:
ChangeListener listener = new ChangeListener() {
#Override
public void changed(ChangeEvent event, Actor actor) {
//play button
if(actor.equals(playBtn)) {
menuMusic.stop();
game.setScreen(new GameScreen(game, assetManager, settingsPrefs));
}
}
}
On desktop mode it works fine but on Android once I click the play button I get these errors (not the full log):
E/AndroidRuntime: FATAL EXCEPTION: GLThread 4474
java.lang.NoClassDefFoundError: com.myname.mygame.worlds.MyContactListener
E/AndroidGraphics: waiting for pause synchronization took too long; assuming deadlock and killing
The error log says that the problem is is the box2d world and it's contact listener, but to me it's all good. I'm thinking it's the ParticleEffect I have quite a few of them and I did not load them properly I just used the Gdx.files.internal(). How do you load Libgdx ParticleEffect on AssetManager?
is there a way for the application to not assume deadlock? so that the application does not close
UPDATE (I found what causes the error)
So I tried to change my code cause I taught the way I coded the game is not that good and still have the same problem on the Android platform. The game run properly and it goes to the menu screen but when you click the play button it crashes. So what I did is added a Box2d world in the menu screen
world = new World(0f, -10f);
Then I got the same error when I try to transition to the game screen
FATAL EXCEPTION: GLThread 8739
Process: com.myname.mygame, PID: 12794
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/badlogic/gdx/physics/box2d/World;
Once I added box2d world to the class I just get the error, the problem is on the World class, so how do I know if the package which contains the class is properly installed? or there are other solutions?
As the documention says:
https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/physics/box2d/World.html,
World has only this constructor
World(Vector2 gravity, boolean doSleep)
So how is it possible that you are creating a World object in that way?
Furthemore, check this answer :
http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=22311
Just to be clear, because my question can be not so clear.
I develop Music Player app. The thing is I have MainActivity and 4 Fragments in this activity(it's not all).
In each fragment I have list of songs retrieved from device using CustomCursorAdapter(for example: first fragment - all songs, second fragment albums e.t.c.)
I already tried to use MediaPlayerSingleton
public class singletonMediaPlayer{
MediaPlayer mediaPlayer;
private static singletonMediaPlayer in = null;
private singletonMediaPlayer() { }
public static singletonMediaPlayergetInstance() {
if (in == null) {
synchronized (singletonMediaPlayer.class) {
if (in == null) {
in = new singletonMediaPlayer();
}
}
}
return instance;
}
}
But here the problem was that all playback controls I have in MainActivity(not in fragments) and have no idea how to handle previouse, next buttons. It is not a problem if media player is in fragment or activity together with ListView of songs but like this... have no idea. Plus when I tried to select item(song) from another activity it just didn't play until I press play button. Playbacks I can see it through all fragments so it's looks like this(just in case):
Plus I have 2 seperate Activities to show songs from albums and from playlists. Sooooooooooo... Finaly the question is:
How do you think it is better to build Media Player for such app (just in case, I don't need code from you). Is it better to use Music Service(which I already started to build) or maybe Singletone is better(in that case I just don't know how to perform the task with singletone for now) or maybe there is another way??? Will be great if somebody response with hint, link or just show me the way in which better to go.
Thank you in advance!
P.S.
Yep, by the way there are 3 ListViews with songs(for now) - 2 of them reusable.
I'm Developing Android Application for Parental Controlling, so I want to disable home and back button. Because kids are unpredictable, their can push home button or back button and so on. Than i want to disable sliding notification bar. (Because notification bar can change device configuration and setting)
I'm planning to create Android Application which is similar to the Samsung Kids Mode-Parental Control.
Is possible to create application like Samsung Kids Mode? Can you give some link/article or even example program to me?
I Have tried this :
#Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
but it not handle home button, the Home button still working.
Thanks in advance to everyone for taking time to read this, hoping a positive solution.
I dont know of anyway to override the home button. Im not sure that it can be done. You can override the back button like so.
#Override
public void onBackPressed() {
//do nothing, important dont call super.onBackPressed
}
Another this you can do is set the app to immersive mode to reduce the chance of accidently exiting the app
https://developer.android.com/training/system-ui/immersive.html
Extended from Activity
#Override
public void onBackPressed() {
}
can be used to override back button. Be sure to remove super.onBackPressed().
My activity_main_layout has 2 buttons:
//Start game on click
<Button android:id="#+id/btnStart"/>
//If not sign in Google Game play Service
//Sign in then show leader board on click
<Button android:id="#+id/btnLeader board" />
Click on btnStart to begin playing game:
btnStart.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
Intent intent = new Intent(MainActivity.this, game_play.class);
startActivity(intent);
finish();
}
});
As you can see, class game_play is the place to play and update height score.
I'm wondering where to extends BaseGameActivity? Inside class MainActivity or game_play or both of them?
I try many times but it's not successfull.
I'm really an amateur, I expect that you give me some ideas.
Have you gone through the QuickStart Guide? This is a good place to start if you are new to developing games for Android. To answer you question, you need to access the Play Game Services from the activity that is going to handle signing in and calling game services APIs.
From your description it sounds like both your activities will need to make calls (the main activity is showing the leaderboard, and the game activity is most likely posting scores).
Extending your activity from BaseGameActivity really is not needed any longer (for an entertaining explanation watch: Death of BasegameActivity. What you do need to do is implement the two interfaces that handle initializing the GoogleAPIClient:
public class MainActivity extends Activity implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
}
To implement these, refer to the samples and the doc: https://developers.google.com/games/services/android/init
You can do the same in your game activity. The application will maintain the login state between activities, so the player will not have to login twice.
I am developing the network application in which I want to run my J2ME MIDP application in background without any GUI so that is any way to construct the application is such manner.
try this
set your current Display to null. so there will not be any form or alert running on the screen. But however your code will be running in the background.
Display display = Display.getDisplay(this); // here 'this' points to Midlet
display.setCurrent(null);
it easy just have a code of line on any event for example in the click of button
Display.getDisplay (this).setCurrent (null);
and return back the control via
Display.getDisplay (this).setCurrent (mycanvas);
Yes this code works Good,
display = Display.getDisplay(this);
public void startApp()
{
display.setCurrent(form);
}
public void pauseApp()
{
}
public void hide()
{
Display.getDisplay (this).setCurrent (null);
}
This is will work like, make a button can after clicking it call hide Function, or you call this hide function in constructor so it will hide itself when app start, can you keep unHide statement in appStart() so if you Tab the program then it will unHide app again.
NOTE: you said you are working on Network app, but some mobile will turn off the Internet Connection, when the Mobile screen Turn Off. please check this. and If you found any solution It will be Good to share here.