I am creating an android application. I have a logo screen(Activity)
and then my home screen(another activity)
. I want that when I start my application my logo screen should come and then automatically after 2 sec my home screen should appear. Can anyone please suggest to me what I should do?
Yes it is. If your requirement are like that then there is no harm in doing that. If you use this then dont forget to call finish(). finish() will remove the activity from backstack so when you press back you dont return to previous instance of same activity.
To allow other apps to start your activity in this way, you need to add an <intent-filter> element in your manifest file for the corresponding <activity> element.
Now in the onResume() method, check if we already have the value of prevStarted in the SharedPreferences. Since it will evaluate to false when the app is launched for the first time, start the MainActivity (Which we want to appear just once) and set the value of prevStarted in the SharedPreferences.
Please use this..
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class Logo extends Activity {
protected boolean _active = true;
protected int _splashTime = 2000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.logo);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
finish();
Intent i3 = new Intent(Logo.this, Home.class);
startActivity(i3);
}
}, _splashTime);
}
}
You can use TimerTask.On TimerTask schedule a task after 2 minutes.And perform the task below
To use Timer Task see the link TimerTask
LogoScreen.this.startActivity(new Intent(LogoScreen.this,HomeScreen.class));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With