When i run application,Login Activity should come only once for first time and next time ,when i open two different Activities should come based on button click in Login Activity.
In login activity i kept two radio buttons if i enable first radio button next time when i opened it should show main2 layout and if i enabled second radio button it should show main3 layout.
public class Demo1 extends Activity {
Button b1,b2;
int count=0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences settings = this.getSharedPreferences("MyApp",0);
boolean firstrun=settings.getBoolean("firstrun",true);
if (firstrun) {
SharedPreferences.Editor e = settings.edit();
e.putBoolean("firstrun",false);
e.commit();
setContentView(R.layout.main1);
}
else{
test();
}
b1=(Button)findViewById(R.id.button1);
b2=(Button)findViewById(R.id.button2);
b1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
count=1;
Intent intent = new Intent(Demo1.this, ButtonActivate1.class);
startActivity(intent);
}
});
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
count=2;
// TODO Auto-generated method stub
Intent intent = new Intent(Demo1.this, ButtonActivate1.class);
startActivity(intent);
}
});
}
private void test() {
// TODO Auto-generated method stub
if(count==1)
{
setContentView(R.layout.main2);
}
if(count==2)
{
setContentView(R.layout.main3);
}
}
}
In this example when i am running it is getting force closed and showing error in the line button.setonclicklistner.please suggest me how to solve this issue.
I have updated my answer to the following. This should work for you now.
The main1.xml file:
I have replaced the onClick listeners to be set within the XML file. I find this neater and easier.
Manifest file: