• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Moe091

Android game doesn't run every other time?

3 posts in this topic

I'm writing an android game and am having a problem when running it from the launcher.

if i start it from eclipse it works every time, but the next time i go to run it from the launcher I just get an unresponsive white screen(probably just my blank surfaceview, or maybe it's not even displaying the surfaceview and it's just my blank activity). After I run it once on the launcher and wait for it to crash and force close, the next time I run it it works fine. The next time after that that I run it from the launcher, I get the white screen again, and the next time it runs fine and so on.

I'm guessing I'm not handling my thread/activity lifecycle correctly, I could be wrong tho as I am very new to android.

heres code for my start activity:

public class GameActivity extends Activity {
GameView game;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.out.println("goin good so far");
SpriteManager.man.setAssets(this.getAssets());
game = new GameView(this);
setContentView(game);
//game.start();

}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

public void onPause() {
super.onPause();
game.pause();
}

public void onResume() {
super.onResume();
game.resume();
}
}



and my start/resume/pause methods in the game class

public void start() {
running = true;
thread.start();
}

public void resume() {
if (!running)
start();
}

public void pause() {

running = false;
while(true) {
try {
thread.join();
} catch (InterruptedException e) {
// retry
}
}
}

running is a volatile boolean. thread is just my main game thread. Right now my code is a little weird because I was messing around with the activity lifecycle trying to fix my problem so theres so random If's and things commented out.

I was hoping someone might be able to point me in the right direction or even help me figure out what to ask google as I haven't been able to find anything relevant to my issue with searches.

thank you, lemme know if you need more info or have questions about my app
0

Share this post


Link to post
Share on other sites
Im thinking i have a problem with pausing/resuming my app. the reason it works every other time is because the app totally crashes and is terminated half the time, then the time after that it starts fresh and runs ok. also when installing it from eclipse the app is reinstalled then started for the first time.

I have the same white screen problem when pausing the activity with the home button and then trying to start it again from the launcher. I checked and onResume is not called when the activity is opened from the launcher for some reason, whether it was paused by the home button or from the back button. onResume is only called when the activity is first run or when it is restarted after a crash. From what I read this is not the default behavior, anyone have any idea why onResume isn't getting called?
0

Share this post


Link to post
Share on other sites
Ok so i figured out then when I pause my activity, it gets stuck in an infinite loop calling thread.join over and over again. which is pretty damn obvious because its in a while(true) loop with no way to get out, but im confused because that code was taken from an android game programming book and works in the example game from the book. Weird.


Im just gonna remove the while loop, but then how am I gonna know if the thread was succesfully stopped? is there any flag I can use instead instead of just true in the while loop to check if it was succesfully joined?
0

Share this post


Link to post
Share on other sites
What this loop is really doing is attempting the call to thread.join() repeatedly until it is successful (if an exception is thrown it is immediately caught, ignored and the loop resumes). However, in the code from your original post there is no way for the loop to exit. It continues looping infinitely even after thread.join() returns. The solution is to add a break; statement just after the call to thread.join() in the try block. This way, the loop terminates once thread.join is successful.

[source lang="java"]while(true) {
try {
thread.join();
break;
} catch (InterruptedException e) {
// retry
}
}[/source]
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0