A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

  1. package com.example.welcome;

  2. import java.util.HashMap;
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.content.SharedPreferences;
  6. import android.content.SharedPreferences.Editor;
  7. import android.content.pm.ApplicationInfo;
  8. import android.content.pm.PackageManager;
  9. import android.content.pm.PackageManager.NameNotFoundException;
  10. import android.os.Bundle;
  11. import android.os.Handler;
  12. import android.widget.Toast;

  13. public class Welcome extends Activity {

  14.         boolean isFirstIn;
  15.         public static String sMallId = "";

  16.         @Override
  17.         protected void onCreate(Bundle savedInstanceState) {
  18.                 super.onCreate(savedInstanceState);
  19.                 setContentView(R.layout.welcome);

  20.                 // SharedPreferences
  21.                 SharedPreferences sp = Welcome.this.getSharedPreferences("SP", MODE_PRIVATE);
  22.                 isFirstIn = sp.getBoolean("isFirstIn", true);
  23.                 if (isFirstIn) {
  24.                         new Handler().postDelayed(new Runnable() {
  25.                                 @Override
  26.                                 public void run() {
  27.                                         goGuide();
  28.                                 }
  29.                         }, 2000);
  30.                         Editor editor = sp.edit();
  31.                         editor.putBoolean("isFirstIn", false);
  32.                         editor.commit();
  33.                 } else {
  34.                         new Handler().postDelayed(new Runnable() {
  35.                                 @Override
  36.                                 public void run() {
  37.                                         goHome();
  38.                                 }
  39.                         }, 2000);
  40.                 }
  41.         }

  42.         private void goHome() {
  43.                 Intent intent = new Intent(Welcome.this, MainActivity.class);
  44.                 Welcome.this.startActivity(intent);
  45.                 Welcome.this.finish();
  46.         }

  47.         private void goGuide() {
  48.                 Intent intent = new Intent(Welcome.this, GuideViewPager.class);
  49.                 Welcome.this.startActivity(intent);
  50.                 Welcome.this.finish();
  51.         }
  52. }
复制代码

今天只写了一个架构,这是其中主要部分的代码实现,利用sharedpreference存储相关信息,能够掌握share店铺reference的使用,其中还利用了多线程技术实现第一次欢迎界面的加载

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马