Monday, September 23, 2013

[android help] Switching a View/Activity after Few seconds


Switching a View/Activity after Few seconds


android - Switching a View/Activity after Few seconds - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
















I want to change the view/Activity of my app after few seconds I mean i have created a home View for my app and i want to move to the next Activity after like 3 seconds, How should I achieve that. Thank You


























try this,



Handler mHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
Intent i = new Intent(FirstActivity.this,SeconActivity.class);
startActivity(i);
};
};
mHandler.sendEmptyMessageDelayed(0, 3000);



























You can make slash Activity. Try this code....hop your problem will solve



public class SplashActivity extends Activity {

private final int SPLASH_DISPLAY_LENGHT = 2000;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.splash_screen);

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(SplashActivity.this, NightClubMain.class);
SplashActivity.this.startActivity(mainIntent);
SplashActivity.this.finish();
}
}, SPLASH_DISPLAY_LENGHT);
}





















You can use Timer for that.



Timer myTimer;

startTimerTask();

public void startTimerTask() {
MyTimerTask myTask = new MyTimerTask();
myTimer = new Timer();
myTimer.schedule(myTask, 0, 3000);

}
@Override
public void onPause() {
super.onPause();
try {
myTimer.cancel();
} catch (Exception e) {
e.printStackTrace();
}

}

@Override
public void onStop() {
super.onStop();
try {
myTimer.cancel();
} catch (Exception e) {
e.printStackTrace();
}
}

class MyTimerTask extends TimerTask {

public void run() {
try {
getActivity().runOnUiThread(new Runnable() {

@Override
public void run() {
//

Do YOUR STUFF HERE
}

});
} catch (Exception e) {
e.printStackTrace();
}

}
}



















default






Read more

stackoverflow.comm



No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...