Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic start of a new activity in android

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?

like image 566
Antrromet Avatar asked Jun 27 '11 06:06

Antrromet


People also ask

Can an activity start itself Android?

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.

How do I start an app from another 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.

How do you start an activity only once the app is opened for the first time?

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.


2 Answers

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);
}
}
like image 138
Nikhil Avatar answered Oct 12 '22 07:10

Nikhil


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));

like image 26
Rasel Avatar answered Oct 12 '22 06:10

Rasel