James_Duh James_Duh - 1 year ago 107
Android Question

Call a Method from another Method Android

I am not sure this workaround is the correct way to achieve my goal of having a prompt text in a spinner. What happens with this application is the spinner navigates to another Activity via an Intent and when the user navigates back to the Main Activity with the spinner they have two ways back. One with a Button and a click event the other by clicking the device BACK button. I am trying to call the code in the click event from the method that manages the device BACK button
I do not know how to call the click event from the device BACK button Method

public void onBackPressed() {
Toast.makeText(getApplicationContext(),"Use BACK BUTTON\n\n"+"On the Screen",Toast.LENGTH_LONG).show();
// I want to call goBack(View view) from here
// +++++++++++++++++++++++++++++++++++++++++++

public void goBack(View view){
Intent i = new Intent( PageTwo.this, MainActivity.class );
startActivity( i );

The reason I use this Intent to navigate BACK to the Main Activity is it reloads the variables in the Spinner

Answer Source

It looks like goBack(View) is most likely from an onClick setup in your layout XML. Since you aren't using the view, just pass null:

@Override public void onBackPressed() {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download