dasd

public class SplashActivity extends Activity {

	private SharedPreferences preferences;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash_activity);

		//实例化SharedPreferences对象
		//MODE_APPEND:模式会检查文件是否存在,存在就往文件追加内容,否则就创建新文件.
		preferences = getSharedPreferences("count", MODE_APPEND);
		
		//读取文件中的count,若没有初始值,设置为0
		int count = preferences.getInt("count", 0);
		//判断count是否为0,是0则进入欢迎界面,否则转到LoginActivity
		if (count == 0) {
			
			//初始化Intent
			Intent intent = new Intent();
			//设置Intent的setClass属性,跳转到指定的Activity
			intent.setClass(getApplicationContext(), WelcomeActivity.class);
			//开启意图
			startActivity(intent);
			//结束当前Activity的生命周期
			finish();
			
			/**Intent另外一种写法
			 * Intent intent = new Intent(SplashActivity.this, WelcomeActivity.class);
				SplashActivity.this.startActivity(intent);
				SplashActivity.this.finish();
			 */
	
			
		} else {
			Intent intent = new Intent();
			intent.setClass(getApplicationContext(), LoginActivity.class);
			startActivity(intent);
			finish();
		}
		//使用SharedPreferences.edit方法获得SharedPreferences.Edit对象
		Editor editor = preferences.edit();
		//通过SharedPreferences.Editor.putInt方法保存key-value对值,让count自动+1
		editor.putInt("count", ++count);
		//调用commit方法才能将key-value对真正保存在相应的文件中
		editor.commit();
	}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值