如何permanetly杀活动按钮后点击使用共享prefrance [英] how to kill Activity permanetly After button click Using Shared prefrance
本文介绍了如何permanetly杀活动按钮后点击使用共享prefrance的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public class MainActivity extends Activity {
Button btn1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent newpage = new Intent(MainActivity.this, PhonrRegistaion.class);
startActivity(newpage);
btn1=(Button)findViewById(R.id.button1);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent myintent=new Intent(MainActivity.this,nextActvity.class);
startActivities(null);
}
});
}
}
这是我的活动,我想从一个活动转移到另一个活动,我想杀死我的活动永久使用共享prefrances意味着如果打开应用就应该推出第二个活动。请帮助我不知道如何使用一丝一毫prefrances杀活动
this is my Activity i want moving from one Activity to another Activity i want to kill my Activity permanently using shared prefrances means if open Application then it should launch second Activity . please help i dont know how to kill Activity using shred prefrances
推荐答案
下面是完整的解决方案。
here is the complete solution
//firstly when you register the user set the shared preferences in your register class like this
//declare pref editor
SharedPreferences prefs;
SharedPreferences.Editor prefsEditor;
prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefsEditor = prefs.edit();
//paste below peace of code when the registration will be success
prefsEditor.putString("register", "yes");
prefsEditor.commit();
//now in your first activity you just check the shared pref value to know the user is register or no
SharedPreferences prefs;
String register;
prefs = PreferenceManager.getDefaultSharedPreferences(this);
register=prefs.getString("register", "");
//now check the value of shared pref and apply the condition like this
Intent intent ;
if(register.equalsIgnoreCase("yes"))
{
intent = new Intent(this, NextAct.class);
startActivity(intent);
finish();
}
else
{
intent = new Intent(this, Register.class);
startActivity(intent);
finish();
}
这篇关于如何permanetly杀活动按钮后点击使用共享prefrance的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文