Выполняется задание в течение фиксированного времени, затем начинается другая анимация

1

Я хочу запустить страницу проектирования до того, как появится экран моего входа... так, как страница проектирования может храниться в течение нескольких секунд?

Теги:

3 ответа

0
Лучший ответ

Для этого вы можете использовать концепцию экрана заставки. См. Следующий код:

public class SplashScreen extends Activity {
    protected boolean _active = true;
    protected int _splashTime = 2000; // time to display the splash screen in ms 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        Thread splashTread = new Thread() {
                @Override
                public void run() {
                    try {
                        int waited = 0;
                        while(_active && (waited < _splashTime)) {
                            sleep(100);
                            if(_active) {
                                waited += 100;
                            }
                        }
                    } catch(InterruptedException e) {
                        // do nothing
                    } finally {
                        finish();

                        startActivity(new Intent("com.live.A"));
                        stop();
                    }
                }
            };
            splashTread.start();
    }

}

где A - экран, который вы хотите отобразить после экрана всплеска, и com.live - это имя вашего пакета

Надеюсь, это поможет вам:)

  • 1
    чувак спасибо за вашу помощь ....
1

Довольно много, как указано выше с 1 добавлением: Touch на экране удаляет spashscreen:

public class SplashScreen extends Activity {

protected boolean _active = true;
protected int _splashTime = 5000; 

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    // thread for displaying the SplashScreen
    Thread splashTread = new Thread() {
        @Override
        public void run() {
            try {
                int waited = 0;
                while(_active && (waited < _splashTime)) {
                    sleep(100);
                    if(_active) {
                        waited += 100;
                    }
                }
            } catch(InterruptedException e) {
                // do nothing
            } finally {
                finish();
                GoToMain();
                stop();
            }
        }
    };
    splashTread.start();
}
public void GoToMain(){
    Intent i = new Intent(this, MainActivity.class);
    startActivity(i);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        _active = false;
    }
    return true;
}

}

MainActivity - это имя следующего действия ofc: -)

Счастливое кодирование

1
 new Handler().postDelayed(new Runnable() {


        public void run() {

            /* Create an Intent that will start the Second-Activity. */

            Intent mainIntent = new Intent(YourFirstActivity.this,
                    YourSecondActivity.class);

            YourFirstActivity.this.startActivity(mainIntent);

            YourFirstActivity.this.finish();

        }

    }, 2000);

Ещё вопросы

Сообщество Overcoder
Наверх
Меню