I have created a splash event and have it set to sleep for 3secs. Everything works fine but when you go to exit the application it takes you back to the splash. Is there a way to kill this with the code that I have or do I need to write this in a different manner.
public class splash extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timer = new Thread(){
public void run(){
try{
sleep(3000);
} catch (InterruptedException e){
e.printStackTrace();
}finally{
Intent openApp = new Intent("com.iqmobile.chris.IQMOBILEACTIVITY");
startActivity(openApp);
}
}
};
timer.start();
}
}
splash.this.finish(); after you start startActivity(openApp);
Intent openApp = new Intent("com.iqmobile.chris.IQMOBILEACTIVITY");
startActivity(openApp);
splash.this.finish();
Second Solution
in AndroidManifest file
<activity android:noHistory="true"
android:name=".splash" />
add finsh(); in code as :
Intent openApp = new Intent("com.iqmobile.chris.IQMOBILEACTIVITY");
startActivity(openApp);
splash.this.finsh();
mSplashThread = new Thread() {
#Override
public void run() {
try {
synchronized (this) {
wait(3000);
}
} catch (InterruptedException ex) {
}
finish();
Intent intent = new Intent();
intent.setClass(FirstActivity.this,
SecondActivity.class);
startActivity(intent);
}
};
mSplashThread.start();
}
Related
I have a problem with my app. I have created a button called "browse". By clicking it, the button performs a google search and the app is no longer visible. Additionally, I have a countdowntimer. Now I want that the countdowntimer pauses as long as the app is not visible.
Do you have any ideas?
I have already tried the methods onPause(); and onResume(); but its not properly working.
browse.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String escapedQuery = null;
resume = true;
countDownTimer.cancel(); //I have no idea where to resume
try {
escapedQuery = URLEncoder.encode(begriff2, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Uri uri = Uri.parse("http://www.google.com/#q=" + escapedQuery);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
You can cancel it ,in onPause() , like this :
#Override
public void onPause() {
countDownTimer.cancel();
super.onPause();
}
I am trying to find a way to skip a flash screen by clicking on the screen of the activity. This is what I came to and it works. The problem is that after I click and the new activity is called, the boolean false default if runs again and the intent is called twice. What am I doing wrong?
RelativeLayout OnClickSkipScreen = (RelativeLayout)findViewById(R.id.SplashScreenView);
OnClickSkipScreen.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
OnClickSkip = true;
/*Loading.interrupt();
Intent SplashScreen = new Intent(SplashScreen.this, HomeScreen.class);
startActivity(SplashScreen);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
finish();*/
}
});
Thread Loading = new Thread() {
#Override
public void run() {
if (!OnClickSkip) {
try {
sleep(2573);
Intent SplashScreen = new Intent(SplashScreen.this, HomeScreen.class);
startActivity(SplashScreen);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
} catch (Exception e) {
e.printStackTrace();
} finally {
finish();
}
} else if (OnClickSkip) {
try {
Intent SplashScreen = new Intent(SplashScreen.this, HomeScreen.class);
startActivity(SplashScreen);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
} catch (Exception e) {
e.printStackTrace();
} finally {
finish();
}
}
}
};
Loading.start();
}
use SharedPreference. Then think is whenever your class loads up it loads your boolean to its initial status which is false. so you will only meet one condition,all the time, which is the condition you are meeting now.
When i say persist, i mean you need to save your boolean state so as you can load it up from storage and check,with this your boolean will not be dependent on the initial state which is always false
so in your oncreate it could be this
SharedPreference sp = getPreference(0);
boolean OnClickSkip = sp.getBoolean("onclick",false);
now you can continue; if you want to save your boolean state
Editor e = sp.edit();
e.putBoolean("onclick",onClickSkip);
e.commit();
now continue to your codes
I have a problem with my game - when the live is 0 it should show the game-over screen and finish the game-activity, but the screen freezes instead.
The code in the surface is:
if(live <= 0){
try {
gameThread.setGameRunning(false);
gameThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
gameOverHandler.post(new Runnable() {
#Override
public void run() {
gameOver.onGameOver(score);
}
});
}
And the Interface in the GameActivity:
#Override
public void onGameOver(int score) {
Intent gameOver = new Intent(this, GameOver.class);
gameOver.putExtra("score", score);
startActivity(gameOver);
gameEngine.stop();
this.finish();
}
The Game-thread loops the canvas drawing and the Engine the movements of the Characters.
I hope you can help me.
Thanks!
You must have initialised gameOverHandler somewhere in the code using
gameOverHandler = new Handler();
or
gameOverHandler = new GameOverHandler();
Try replacing it with
gameOverHandler = new Handler(Looper.getMainLooper());
or
gameOverHandler = new GameOverHandler(Looper.getMainLooper());
depending on what class you have actually used.
Sry my internet was down about the weekend i've solved it with the constructor
public GameSurface(Context context, OnGameOver onGameOver){
...
}
and in the MainActivity
gameSurface = new GameSurface(this, this);
and implementing OnGameOver
a litte bit rewrite for my code but its works...
I have made 4 activities in android they all are same. They just have a relative layout and that layout has 4 different images as backgroud,i have set animation on that for 2000miliseconds for example 1st screen should come from right.second from left...etc..I have implemented as below but its not working pls help me..!
screen1.java
Thread splashThread = new Thread() {
public void run() {
try {
sleep(2000);
} catch (Exception e) {
}
startAnimatedActivity(new Intent(SplashActivity1.this,
SplashActivity2.class),
CustAnimatedActivity.SLIDE_FROM_RIGHT);
finish();
}
};
splashThread.start();
same code for 3 activity also..!
i have used "handler" in place of "thread" .I have tried following code..and its working like butter..!
new Handler().postDelayed(new Runnable()
{
#Override
public void run()
{
handler.sendEmptyMessage(1);
}
}, 2000);
}
private Handler handler = new Handler()
{
#SuppressWarnings("deprecation")
#Override
public void handleMessage(android.os.Message msg)
{
try
{
Intent intent = null;
intent = new Intent(SplashActivity1.this,
SplashActivity2.class);
startActivity(intent);
overridePendingTransition(R.anim.animated_activity_slide_left_in, R.anim.animated_activity_slide_right_out);
finish();
} catch (Exception e) {
}
}
};
I am trying to wait untill the spalsh screen will be over abd then when get the result from splash go to anther activity bu my code not wating for splash (AsyncTask) just going for what after to intent.
Hope you can help.
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String nextActivity=new String();
Thread splashTread = new Thread() {
#Override
public void run() {
try {
splash splash=(tools.splash) new splash(first.this).execute();
int waited = 0;
while(splash.running && (waited< getResources().getInteger(R.integer.splashTimeOut)))
{
sleep(100);
if(splash.running) {
waited += 100;
}
// nextActivity=splash.newActivity;
}
Intent intent = new Intent(first.this,Class.forName("activities.third"));
startActivity(intent);
} catch(InterruptedException e) {
// do nothing
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
finish();
}
}
};
splashTread.start();
try {
Intent intent = new Intent(first.this,Class.forName("activities.third"));
startActivity(intent);
Use this code
Intent intent = new Intent(first.this,Class.forName("activities.third"));
startActivity(intent);
inside finally before finish() instead of start try block;