Android判斷介面

來源:互聯網
上載者:User

標籤:android   style   class   c   tar   ext   

     仿造,第一次進入去引導介面,否則進啟動介面。

package edu.hpu.init;
import edu.hpu.logic.R;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
public class TellActivity extends Activity {
boolean isFirstIn = false;
private static final int GO_HOME = 1000;
private static final int GO_GUIDE = 1001;
// 延遲3秒
private static final long delayTime = 3000;
private static final String spName = "first_pref";
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case GO_HOME:
goHome();
break;
case GO_GUIDE:
goGuide();
break;
}
super.handleMessage(msg);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
init();
}
private void init() {
// 讀取SharedPreferences中需要的資料
// 使用SharedPreferences來記錄程式的使用次數
//介面,MODE_PRIVATE指定該SharedPreferences資料只能被本應用程式讀、寫
SharedPreferences preferences = getSharedPreferences(
spName, MODE_PRIVATE);
SharedPreferences.Editor editor; 
editor = preferences.edit();
// 取得相應的值,如果沒有該值,說明還未寫入,用true作為預設值
isFirstIn = preferences.getBoolean("isFirstIn", true);
// 判斷程式第幾次運行,如果是第一次運行則跳轉到引導介面,否則跳轉到主介面
if (!isFirstIn) {
mHandler.sendEmptyMessageDelayed(GO_HOME, delayTime);
} else {
// 使用Handler的postDelayed方法,3秒後執行GuideActivity
mHandler.sendEmptyMessageDelayed(GO_GUIDE, delayTime);
editor.putBoolean("isFirstIn", false);
editor.commit();
}
}
private void goHome() {
Intent intent = new Intent(this, StartActivity.class);
startActivity(intent);
this.finish();
}
private void goGuide() {
Intent intent = new Intent(this, GuideActivity.class);
startActivity(intent);
this.finish();
}
}
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.