When i press button in second Activity, intent sends a string to the MainActivity. It's in onClick method:
Intent intent = new Intent(this, MainActivity.class);
String wynik = "clear";
intent.putExtra("clearList", wynik);
and main activity, in onCreate method:
Intent intent2 = getIntent();
wynik = intent2.getStringExtra("clearList");
if (wynik.equals("clear")) {
tempLukasz = 0;
tempMarcelina = 0;
tempKarolina = 0;
foodCategorySum = 0;
catCategorySum = 0;
othersCategorySum = 0;
lukaszJedzenie = 0;
lukaszKot = 0;
lukaszInne = 0;
marcelinaJedzenie = 0;
marcelinaKot = 0;
marcelinaInne = 0;
karolinaJedzenie = 0;
karolinaKot = 0;
karolinaInne = 0;
newPayments.clear();
wynik = "";
}
so when MainActivity receives this "clear" message it should set my numbers to 0 and clear the list. Pic.1 is example of my main activity window:
and in second pic is what i want to have AFTER button in second activity is pressed
Unfortunately it does not work: this line throws NullPointerException:
if (wynik.equals("clear")) {
Any ideas where am I making a mistake ? I thought that checking if ( getIntent() != null ) will solve this or just surrount my IF clase with try-catch but it does not work either.