0

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

4

4 回答 4

2

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);
于 2013-09-23T06:29:40.183 回答
0
view.postDelayed(Runnable r, int delay);
于 2013-09-23T06:29:27.127 回答
0

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);
}
于 2013-09-23T06:30:25.467 回答
0

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

        }
    }
于 2013-09-23T06:30:44.253 回答