public class MainActivity extends ActionBarActivity {
Button b1;
TextView tv2;
Integer count ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
count++;
b1= (Button)findViewById(R.id.b1);
tv2=(TextView)findViewById(R.id.tv2);
tv2.setText(count);
if(count == 5) {
Intent ii = new Intent(this,Activity2.class );
Bundle bb = new Bundle();
bb.putInt("Count",count);
ii.putExtras(bb);
startActivity(ii);
finish();
}
else
{
Intent iii = new Intent(this,activity3.class);
// Bundle bb1 = new Bundle();
startActivity(iii);
}
}
public void onStart()
{
Bundle b33 = getIntent().getExtras();
count=b33.getInt("count");
tv2.setText(count);
}
in this code i want to count the number of times an activity is opened in this case activity1 will open only 5 times and after that activity3 will open what i m trying is killing the activity1 before killing i m sending the count value to the activity2 and after that i m calling again activity1 and again i m sending the count value to activity1 so the code will be executed from the start itself so again the value will be 1 but i want activity1 to catch the new values of count in oncreate() or in onstart()
and the error is the app is not opening its force closing and in logcat Null-exception error is displayed although i did all the bindings.
try this code at onStart() method
change:
to
also change:
to(in both place onCreate and onStart):
Updated code:
i tried this code and its working.