Android开发实践(四)App的欢迎界面

要实现的逻辑是这样的,首先运行App去到欢迎页面,在欢迎页面判断两小时之内有没有登陆过,有就不用验证登陆,直接到主页,没有就跳登陆页面

在这过程中用到了一个:SharedPreferences

welcome的布局页面:就一张欢迎图片

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/mainpage"
    android:id="@+id/main">  
</RelativeLayout>

activity

import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.os.Handler;
  
 
public class WelcomePage extends Activity {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome);
        // 延迟几秒,然后跳转到登录页面
        new Handler().postDelayed(r, 3000);
    }
 
    Runnable r = new Runnable() {
        @Override
        public void run() {
        	 
            SharedPreferences preferences=getSharedPreferences("user",MODE_PRIVATE);
            String Status=preferences.getString("Status", "0");
            Intent intent = new Intent();
            if(Status=="0"){
            	
             intent.setClass(WelcomePage.this, MainActivity.class);   //去登录页面
          
            }else{
            	Method method=	new Method();
            	//Date dafultDate=new Date("1900-1-1");
             boolean  isLogin=method.DateCompare(preferences.getString("LastDate", "1900-1-1 00:00:00"));
               
                 if(!isLogin){ 
            		  intent.setClass(WelcomePage.this, MainActivity.class);   //去登录页面
         		}else{
         			 //记录当前时间
         		     SimpleDateFormat formatter=new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");
         			 Date  curDate=new Date(System.currentTimeMillis());
         		     String  strDate= formatter.format(curDate); 
         			 Editor editor=preferences.edit(); 
         			 editor.putString("LastDate", strDate);
                     editor.commit();
                     
         			 intent.setClass(WelcomePage.this, TextWebWiew.class);  //去首页
         		} 
            } 
            startActivity(intent);
            finish();
        }
    };
 
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值