android 判断APP是否第一次打开

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_31939617/article/details/76899427
package com.example.isfirstrun;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends Activity {

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      SharedPreferences sharedPreferences=this.getSharedPreferences("share",MODE_PRIVATE);
      boolean isFirstRun=sharedPreferences.getBoolean("isFirstRun", true);
      Editor editor=sharedPreferences.edit();
      if(isFirstRun){
         Toast.makeText(MainActivity.this, "第一次运行", Toast.LENGTH_SHORT).show();
         editor.putBoolean("isFirstRun", false);
         editor.commit();
      }else{
         Toast.makeText(MainActivity.this, "不是第一次运行", Toast.LENGTH_SHORT).show();
      } 
   }
}
源码下载
http://download.csdn.net/detail/qq_31939617/9924674 
阅读更多

没有更多推荐了,返回首页