黑马程序员技术交流社区
标题:
android APP实现首次安装欢迎界面
[打印本页]
作者:
android_vae
时间:
2016-5-29 11:21
标题:
android APP实现首次安装欢迎界面
package com.example.welcome;
import java.util.HashMap;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Toast;
public class Welcome extends Activity {
boolean isFirstIn;
public static String sMallId = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
// SharedPreferences
SharedPreferences sp = Welcome.this.getSharedPreferences("SP", MODE_PRIVATE);
isFirstIn = sp.getBoolean("isFirstIn", true);
if (isFirstIn) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
goGuide();
}
}, 2000);
Editor editor = sp.edit();
editor.putBoolean("isFirstIn", false);
editor.commit();
} else {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
goHome();
}
}, 2000);
}
}
private void goHome() {
Intent intent = new Intent(Welcome.this, MainActivity.class);
Welcome.this.startActivity(intent);
Welcome.this.finish();
}
private void goGuide() {
Intent intent = new Intent(Welcome.this, GuideViewPager.class);
Welcome.this.startActivity(intent);
Welcome.this.finish();
}
}
复制代码
今天只写了一个架构,这是其中主要部分的代码实现,利用sharedpreference存储相关信息,能够掌握share店铺reference的使用,其中还利用了多线程技术实现第一次欢迎界面的加载
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2