MainActivity
public class MainActivity extends AppCompatActivity {
private SharedPreferences sha;
private SharedPreferences.Editor editor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sha = getSharedPreferences("quzhi", MODE_PRIVATE);
editor = sha.edit();
//取值
boolean yy = sha.getBoolean("yy", false);
if (yy)
{
Intent intent=new Intent(MainActivity.this,Second_Activity.class);
startActivity(intent);
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//SharedPreferences存值
editor.putBoolean("yy",true);
editor.commit();
Intent intent=new Intent(MainActivity.this,Second_Activity.class);
startActivity(intent);
}
},3000);
}
}