知道我使用按钮从活动移动到另一个
PS我是android的新手,所以要善良
public class swipe2 extends AppCompatActivity implements View.OnClickListener
private Button next,skip;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.swipe2);
next = (Button) findViewById(R.id.next2);
skip=(Button) findViewById(R.id.skip2);
next.setOnClickListener(swipe2.this);
skip.setOnClickListener(swipe2.this);
}
我在这里使用这个按钮
@Override
public void onClick(View v)
{
if(v==next)
{
Intent homeIntent = new Intent(swipe2.this, swipe3.class);
startActivity(homeIntent);
finish();
}
else
{
Intent homeIntent = new Intent(swipe2.this, lastswipe.class);
startActivity(homeIntent);
finish();
}
}
那么我该怎么办才能解决?
答案 0 :(得分:1)
您可以使用shared preferences
将另一个活动称为 StarterActivity.java
在onCreate里面添加这些行;
if(isFirstTime()){
//start the activity you want to have for the first run only
}
else
{
SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_ NAME,
MODE_PRIVATE).edit();
editor.putBoolean("first_time", false);
editor.apply();
//start your main activity here
}
private boolean isFirstTime(){
SharedPreferences prefs = getSharedPreferences(MY_PREFS_
NAME, MODE_PRIVATE);
boolean firstTime= prefs.getBoolean("first_time", true);
return firstTime;
}
别忘了将它添加到manefist并将其作为启动器活动。