Activity Keeps Refreshing

Put your problem here if it does not fit any of the other categories.

Activity Keeps Refreshing

Postby wahid2oo9 » Thu Feb 24, 2011 10:29 am

Hi guys, i have a game using class/activitie pages, everytime i go through them for some reason i dont know what line is the error myself, the application works fine but when i go through activities for some reason sometimes u click a button on a activity and then it just flashes & the same activity shows and u have to click the button again to make it go next activity, and when u exit from the app, my htc desire hd just reloads the phone home screen with a full white background and the green htc in the center?? And has no errors or force close poppin up?
ill show one of my activity code below if u find somethin wrong.

package com.falling.inair;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.View;
import android.content.Intent;
import android.view.View.OnClickListener;
import android.widget.Button;



public class Q1 extends Activity {

// ===========================================================
// Fields
// ===========================================================

private final int SPLASH_DISPLAY_LENGHT = 2300;
private Runnable myRunnable;
private Handler myHandler;

// ===========================================================
// "Constructors"
// ===========================================================

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.q1);


/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
myRunnable = new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(Q1.this,Fail.class);
Q1.this.startActivity(mainIntent);
Q1.this.finish();
}
};

myHandler = new Handler();
myHandler.postDelayed(myRunnable, SPLASH_DISPLAY_LENGHT);






Button failButton = (Button)findViewById(R.id.fail);
failButton.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
Intent StartGameIntent = new Intent(Q1.this,Fail.class);
startActivity(StartGameIntent);
myHandler.removeCallbacks(myRunnable);

}
});


Button failtwoButton = (Button)findViewById(R.id.failtwo);
failtwoButton.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
Intent StartGameIntent = new Intent(Q1.this,Fail.class);
startActivity(StartGameIntent);
myHandler.removeCallbacks(myRunnable);

}
});


Button passButton = (Button)findViewById(R.id.pass);
passButton.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
Intent StartGameIntent = new Intent(Q1.this,Q2.class);
startActivity(StartGameIntent);
myHandler.removeCallbacks(myRunnable);

}
});

Button failthreeButton = (Button)findViewById(R.id.failthree);
failthreeButton.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
Intent StartGameIntent = new Intent(Q1.this,Fail.class);
startActivity(StartGameIntent);
myHandler.removeCallbacks(myRunnable);

}
});

}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
moveTaskToBack(false);
return true;
}
return super.onKeyDown(keyCode, event);
}


thanks
Wahid
wahid2oo9
Developer
Developer
 
Posts: 36
Joined: Fri Dec 31, 2010 7:07 am

Top

Re: Activity Keeps Refreshing

Postby blundell » Thu Feb 24, 2011 11:13 pm

W T F is that code supposed to do?

It starts a new thread that attempts to start a static intent of a new activity?

Please tell us what your aim was ...
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: Activity Keeps Refreshing

Postby wahid2oo9 » Sat Feb 26, 2011 2:52 am

ok sorry, I'm creating a game,
How it starts is.

You click on a activity (New Game) and it takes you to another activity (Question one), and it asks you a question and gives you two or three choices of answers, u have to press the right answer before the timelimit ends or it takes you to another page (FAIL page).

Everything works fine and sometimes i can go through it without making my phone refresh but if i just keep clicking button the activity refreshes and it just makes my phone refresh in the background?


SORRY what i mean by refresh, for an example: I have page1, page2, page3.
I click on a button on page1. the page just flashes like its going to page2 but just goes back to page1.
and if i exit the application... I see my phone refreshing, example: SEE Link for image below
http://www.ihelplounge.com/.a/6a0120a61 ... 970b-800wi
exactly like that then it goes to a screen like the image below
http://tourdefranceorbust.files.wordpre ... =265&h=326
but before it shows anything on the screen its just the background and on the center "Loading..." then the icons and time/date etc shows.
wahid2oo9
Developer
Developer
 
Posts: 36
Joined: Fri Dec 31, 2010 7:07 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 20 guests