3
A
回答
3
下面是一個簡單的閃屏實現:
public class SplashScreen extends Activity {
private Handler mHandler;
private long delay = 1000;
private int i = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_splash_screen);
Timer timer = new Timer();
timer.schedule(task, delay);
}
TimerTask task = new TimerTask() {
@Override
public void run() {
Intent in = new Intent().setClass(SplashScreen.this,
LoginActivity.class).addFlags(
Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(in);
finish();
}
};
}
變量延遲指示切換到另一個之前,你的閃屏活動的暫停時間。
1
0
這裏我附了閃屏initalize基於位置的應用程序的完整代碼。
public class splashScreen extends Activity {
private LocationManager locationManager = null;
private LocationListener locationListener = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
// Start the Animation of SplashScreen
new Handler().postDelayed(new Runnable() {
public void run() {
ImageView imageView = (ImageView) findViewById(R.id.splashImageView);
AnimationDrawable animation = (AnimationDrawable) imageView.getDrawable();
animation.start();
}
}, 500);
// Obtain user's location
new Handler().post(new Runnable() {
public void run() {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
String locationProvider = LocationManager.GPS_PROVIDER;
locationManager.requestLocationUpdates(locationProvider, 1000, 0, locationListener);
try { wait(5000); } catch (Exception e) {}
if(locationManager != null) {
locationManager.removeUpdates(locationListener);
}
}
});
// Start the Tabs screen.
new Handler().postDelayed(new Runnable() {
public void run() {
Bundle extras = new Bundle();
extras.putDouble(Constants.LATITUDE, ((MyLocationListener)locationListener).getLat());
extras.putDouble(Constants.LONGITUDE, ((MyLocationListener)locationListener).getLng());
Intent intent = new Intent(splashScreen.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtras(extras);
startActivity(intent);
}
}, 5000);
}
}
相關問題
- 1. 顯示一次歡迎屏幕鈦
- 2. IIS7在Firefox中顯示歡迎屏幕,Internet Explorer正常工作
- 3. Android歡迎屏幕 - 多張圖片
- 4. 只有一次歡迎屏幕上android
- 5. 歡迎屏幕Like Spotify
- 6. 如何擺脫Atom的歡迎屏幕
- 7. 如何製作歡迎屏幕
- 8. Beagleboard在第一次啓動時不顯示歡迎屏幕
- 9. 我沒有在我的Android Studio打開之前顯示歡迎屏幕
- 10. Facebook Messenger平臺歡迎屏幕沒有顯示
- 11. 如何在科爾多瓦應用程序中顯示歡迎屏幕或教程屏幕
- 12. 在TabBarController之前加載歡迎屏幕(初始屏幕)
- 13. Android:如何在所有活動中顯示歡迎名稱
- 14. Android教育歡迎屏幕 - 帶文本的藍色圓圈突出顯示
- 15. 試圖創建歡迎屏幕與AsyncTask
- 16. GIT GUI無法訪問歡迎屏幕
- 17. 更改Emacs歡迎啓動/屏幕
- 18. Eclipse rcp:歡迎頁面每次如何全屏顯示?
- 19. 如何顯示Pharo 2歡迎信息?
- 20. 滑動屏幕上的移動物體的歡迎屏幕
- 21. 如何創建一個好的GUI爲歡迎屏幕
- 22. 在c#中向客戶端屏幕發送歡迎消息
- 23. 如何啓動鈦應用程序移植到Android不歡迎Appcelerator屏幕?
- 24. 如何在php中顯示消息歡迎'用戶登錄'?
- 25. 如何在我的iPhone應用程序中製作歡迎屏幕?
- 26. Android adMob顯示在屏幕中間
- 27. 在Android中顯示TextView屏幕底部
- 28. 視頻屏幕未在Android中顯示
- 29. 初始屏幕(歡迎)在選項卡視圖之前
- 30. Dynamics CRM中的自定義歡迎屏幕
2-3秒或屏幕? – ice911 2011-02-14 15:51:06