Android Studio 1-7 SharedPreferences存储 与 SD卡存储
今天主要学习了 SP存入SD卡 的应用 主要有如下几点
今日项目——app的引导页
最后一页时 可以选择主动跳过 或者等待五秒后自动跳转
并且 在第二次开启app时 不再显示 紧接着咱们来看看效果
主要逻辑在于将数据存入SD卡 记得加权限 话不多说 up code
1、MainActivity布局与java代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v4.view.ViewPager
android:id="@+id/vp"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
<LinearLayout
android:id="@+id/lin_id"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignBottom="@id/vp"
android:layout_marginBottom="200dp"></LinearLayout>
</RelativeLayout>
package com.example.app2;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.example.app2.fragment.OneFragment;
import com.example.app2.fragment.ThreeFragment;
import com.example.app2.fragment.TwoFragment;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends AppCompatActivity {
private ViewPager vp;
private List<Fragment> list = new ArrayList<>();
private List<ImageView> image = new ArrayList<>();
private Handler handler = new Handler();
private LinearLayout linId;
private boolean flag;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vp = (ViewPager) findViewById(R.id.vp);
linId = (LinearLayout) findViewById(R.id.lin_id);
SharedPreferences name = getSharedPreferences("name", MODE_PRIVATE);
flag =