Sens intent with action and also when back pressed

This commit is contained in:
Sebastián Katzer 2016-08-01 17:02:17 +02:00
parent 0fb7c4530f
commit daa7112642

View File

@ -57,6 +57,12 @@ public final class SelectPrinterActivity extends Activity {
public static final String EXTRA_PRINTER_ID = public static final String EXTRA_PRINTER_ID =
"INTENT_EXTRA_PRINTER_ID"; "INTENT_EXTRA_PRINTER_ID";
/**
* The action of the intent.
*/
public static final String ACTION_SELECT_PRINTER =
"ACTION_SELECT_PRINTER";
/** /**
* Reference to the main view which lists all discovered printers. * Reference to the main view which lists all discovered printers.
*/ */
@ -99,6 +105,15 @@ public final class SelectPrinterActivity extends Activity {
super.onDestroy(); super.onDestroy();
} }
/**
* Sent intent with empty result.
*/
@Override
public void onBackPressed() {
onPrinterSelected(null);
super.onBackPressed();
}
/** /**
* Sends an intent with the specified printer back to the owning activity * Sends an intent with the specified printer back to the owning activity
* and finishes that activity. * and finishes that activity.
@ -110,6 +125,7 @@ public final class SelectPrinterActivity extends Activity {
Intent intent = new Intent(); Intent intent = new Intent();
intent.putExtra(EXTRA_PRINTER_ID, printerId); intent.putExtra(EXTRA_PRINTER_ID, printerId);
intent.setAction(ACTION_SELECT_PRINTER);
setResult(RESULT_OK, intent); setResult(RESULT_OK, intent);
finish(); finish();