Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void selectDestination(View view){
- //add if clause to check if we are already in destination
- Intent intent = new Intent(this, destinationActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
- intent.putExtra("car_obj", (Parcelable) car);
- startActivityForResult(intent, 1);
- }
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == 1) {
- if(resultCode == RESULT_OK){
- if(data.getParcelableExtra("car_obj") != null)
- car = (Car) data.getParcelableExtra("car_obj");
- }
- }
- }
- ///Started Activity///
- Intent intent = getIntent();
- if(intent.getParcelableExtra("car_obj") != null) {
- if (car == null) car = (Car) intent.getParcelableExtra("car_obj");
- }
- else{ //load from file if no intent and no result
- CarFileManager cfm = CarFileManager.getInstance();
- cfm.setFile(getBaseContext());
- cfm.loadCar(getBaseContext());
- car = cfm.getCar();
- }
- intent.removeExtra("car_obj");
- @Override
- public void onBackPressed(){
- Intent intent = new Intent(this, destinationActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
- intent.putExtra("car_obj", (Parcelable) car);
- setResult(RESULT_OK, intent);
- super.onBackPressed();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement