Transfer data to "Choose activity" when I press back button

Viewed 183

Now I run new Intent and transfer data to "PlayTravelledRouteActivity" through button in "MainActivity" like in this graph:

CLICK

But I want run new Intent from "Choose Activity" so I think that I should previously transfer data to "Choose Activity" and next to "PlayTravelledRouteActivity", but to get to "Choose Activity" from "MainActivity" I need click (smartphone) back button like in this graph:

CLICK

And ofc I know where insert code for transfer data from "Choose Activity" to "PlayTravelledRouteActivity" (in button "Play" onClickListener), but I don't know where I should insert this code:

/** lat_GPS,lon_GPS,roll_angle,pitch_angle -> double[] = new double[600], licznik -> int **/
Intent intent1 = new Intent(this, ChooseActivity.class);
intent1.putExtra("lat",lat_GPS);
intent1.putExtra("lon",lon_GPS);
intent1.putExtra("last_index",licznik);
intent1.putExtra("roll_angle",roll_Kalman_Filter);
intent1.putExtra("pitch_angle",pitch_Kalman_Filter);
startActivity(intent1);

to transfer data to "Choose Activity" from "MainActivity" ? Could someone tell me?

1 Answers

According to your question you can use onBackPressed()

Called when the activity has detected the user's press of the back key. The default implementation simply finishes the current activity, but you can override this to do whatever you want.

@Override
   public void onBackPressed() 
    {
        //super.onBackPressed();
        Intent intent1 = new Intent(this, ChooseActivity.class);
        intent1.putExtra("lat",lat_GPS);
        intent1.putExtra("lon",lon_GPS);
        intent1.putExtra("last_index",licznik);
        intent1.putExtra("roll_angle",roll_Kalman_Filter);
        intent1.putExtra("pitch_angle",pitch_Kalman_Filter);
        startActivity(intent1);
    }
Related