几秒钟后切换视图/活动

时间:2013-09-23 06:27:17

标签: android view android-activity

我想在几秒钟后更改我的应用的视图/活动 我的意思是我为我的应用程序创建了一个主视图,我希望在3秒后移动到下一个活动,我应该如何实现。 谢谢

4 个答案:

答案 0 :(得分:2)

试试这个,

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

答案 1 :(得分:0)

view.postDelayed(Runnable r, int delay);

答案 2 :(得分:0)

您可以进行斜线活动。试试这个代码....跳你的问题将解决

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

答案 3 :(得分:0)

你可以使用Timer。

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

        }
    }