I am working on android activity life-cycle
. But i have a problem with connections.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
speedValue = (TextView) findViewById(R.id.speed_value);
rpmValue = (TextView) findViewById(R.id.rpm_value);
}
@Override
public void onResume(){
Intent intent = getIntent();
Bundle input = intent.getExtras();
displayOperations(input);
super.onResume();
}
public void displayOperations(Bundle input){
boolean flag = input.getBoolean("flag");
if(flag){
for (int i = 0; i < input.getStringArrayList("second").size(); i++) {
rpmValue.setText(input.getStringArrayList("rpm").get(i));
speedValue.setText(input.getStringArrayList("speed").get(i));
}
}
}
//Menünün içeriği burada ayarlanır.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent;
switch (item.getItemId()) {
case R.id.action_settings:
intent = new Intent(this, Settings.class);
startActivity(intent);
return true;
case R.id.load_button:
intent = new Intent(this, Operations.class);
startActivity(intent);
onStop();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
In this code im tying to get information from other activity. have to go that class and do some operations then come to our main class to be success. Our bundle comes from other activity as you see. There problem occurs right here. My bundle comes null because i couldnt go to second activity.
When i try onResume, application crushes because of null pointer. How can i solve this issue
LOGCAT
Attempt to invoke virtual method 'boolean android.os.Bundle.getBoolean(java.lang.String)'
on a null object reference
at com.akaydin.berkin.carmonitor.MainActivity.displayOperations(MainActivity.java:42)
at com.akaydin.berkin.carmonitor.MainActivity.onResume(MainActivity.java:36)