I have made this application where when you first open it you will have to put in your number. Next time you open the app it will then skip this first activity where you put in your number. Now in my frontpageactivity i have made an actionbar where i have a menu item where i want to be able to get back and edit the entered number (in the first activity),but in my oncreate i check if there's a number inserted, and if there is, it will skip this page. Is there some way i can say if i came to this activity from the actionbar it should override this or should i find another way to code this, I cannot really work this one out. any help is appreciated!
this is an idea i have been puzzling with, but i not sure if there is such a thing as how long the app has been running
if (appHasBeenRunningForMoreThan10Seconds & !number.equals(NA))
{
textViewNumber.SetText(number) (just to show the number which is allreadyt here)
}
else if (!number.equals(NA)) {
Intent intent = new Intent(this, FrontPageActivity.class);
startActivity(intent);
finish();
}
Source code:
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class PhoneNumberActivity extends Activity {
private static final String NUMBER = "number";
private static final String MY_PREF = "myPref";
private static final String NA = "NA";
private String number;
private EditText phoneNumberEditText;
private SharedPreferences sharedPref;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_phone_number);
phoneNumberEditText = (EditText) findViewById(R.id.phoneNumberEditText);
checkStatus();
if (!number.equals(NA)) {
Intent intent = new Intent(this, FrontPageActivity.class);
startActivity(intent);
finish();
}
}
public void checkStatus() {
sharedPref = getSharedPreferences(MY_PREF, MODE_PRIVATE);
number = sharedPref.getString(NUMBER, NA);
}
public void goToFrontPage(View v) {
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString(NUMBER, phoneNumberEditText.getText().toString());
editor.apply();
Intent intent = new Intent(this, FrontPageActivity.class);
startActivity(intent);
finish();
}
}