Issue 336: set Intent flag to make sure task's launched activities don't stay on...
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Mon, 1 Mar 2010 15:19:45 +0000 (15:19 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Mon, 1 Mar 2010 15:19:45 +0000 (15:19 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1230 59b500cc-1b3d-0410-9834-0bbf25fbcc57

android/src/com/google/zxing/client/android/CaptureActivity.java
android/src/com/google/zxing/client/android/CaptureActivityHandler.java
android/src/com/google/zxing/client/android/HelpActivity.java
android/src/com/google/zxing/client/android/book/BrowseBookListener.java
android/src/com/google/zxing/client/android/history/HistoryManager.java
android/src/com/google/zxing/client/android/result/ResultHandler.java
android/src/com/google/zxing/client/android/share/AppPickerActivity.java
android/src/com/google/zxing/client/android/share/BookmarkPickerActivity.java
android/src/com/google/zxing/client/android/share/ShareActivity.java

index 7b0923b..8198642 100755 (executable)
@@ -151,6 +151,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
       new DialogInterface.OnClickListener() {
     public void onClick(DialogInterface dialogInterface, int i) {
       Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.zxing_url)));
+      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
       startActivity(intent);
     }
   };
@@ -333,6 +334,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
     switch (item.getItemId()) {
       case SHARE_ID: {
         Intent intent = new Intent(Intent.ACTION_VIEW);
+        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
         intent.setClassName(this, ShareActivity.class.getName());
         startActivity(intent);
         break;
@@ -344,12 +346,14 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
       }
       case SETTINGS_ID: {
         Intent intent = new Intent(Intent.ACTION_VIEW);
+        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
         intent.setClassName(this, PreferencesActivity.class.getName());
         startActivity(intent);
         break;
       }
       case HELP_ID: {
         Intent intent = new Intent(Intent.ACTION_VIEW);
+        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
         intent.setClassName(this, HelpActivity.class.getName());
         startActivity(intent);
         break;
@@ -524,6 +528,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
       // Hand back whatever action they requested - this can be changed to Intents.Scan.ACTION when
       // the deprecated intent is retired.
       Intent intent = new Intent(getIntent().getAction());
+      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
       intent.putExtra(Intents.Scan.RESULT, rawResult.toString());
       intent.putExtra(Intents.Scan.RESULT_FORMAT, rawResult.getBarcodeFormat().toString());
       Message message = Message.obtain(handler, R.id.return_scan_result);
@@ -557,6 +562,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
       if (currentVersion > lastVersion) {
         prefs.edit().putInt(PreferencesActivity.KEY_HELP_VERSION_SHOWN, currentVersion).commit();
         Intent intent = new Intent(Intent.ACTION_VIEW);
+        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);        
         intent.setClassName(this, HelpActivity.class.getName());
         startActivity(intent);
         return true;
index c9d85fe..362881c 100755 (executable)
@@ -92,7 +92,9 @@ public final class CaptureActivityHandler extends Handler {
         break;
       case R.id.launch_product_query:
         String url = (String) message.obj;
-        activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
+        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
+        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);        
+        activity.startActivity(intent);
         break;
     }
   }
index 612a0df..cf56fd8 100644 (file)
@@ -60,7 +60,9 @@ public final class HelpActivity extends Activity {
 
   private final DialogInterface.OnClickListener groupsListener = new DialogInterface.OnClickListener() {
     public void onClick(DialogInterface dialogInterface, int i) {
-      HelpActivity.this.startActivity(new Intent(Intent.ACTION_VIEW, BUGGY_URI));
+      Intent intent = new Intent(Intent.ACTION_VIEW, BUGGY_URI);
+      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);              
+      HelpActivity.this.startActivity(intent);
     }
   };
 
index 2f19463..fc56c18 100644 (file)
@@ -47,8 +47,9 @@ final class BrowseBookListener implements AdapterView.OnItemClickListener {
       String readBookURI = "http://books.google." +
           LocaleManager.getBookSearchCountryTLD() +
           "/books?id=" + volumeId + "&pg=" + pageId + "&vq=" + query;
-      activity.startActivity(new Intent(Intent.ACTION_VIEW,
-          Uri.parse(readBookURI)));
+      Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(readBookURI));
+      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);                    
+      activity.startActivity(intent);
     }
   }
 }
index 5bc5c33..8e861dd 100644 (file)
@@ -93,6 +93,7 @@ public final class HistoryManager {
         } else if (i == dialogItems.length - 2) {
           String history = buildHistory();
           Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
+          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);          
           intent.putExtra(Intent.EXTRA_SUBJECT, res.getString(R.string.history_email_title));
           intent.putExtra(Intent.EXTRA_TEXT, history);
           intent.setType("text/plain");
index 42b6b7a..c5bd511 100644 (file)
@@ -339,6 +339,7 @@ public abstract class ResultHandler {
 
   void launchIntent(Intent intent) {
     if (intent != null) {
+      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
       try {
         activity.startActivity(intent);
       } catch (ActivityNotFoundException e) {
index f02b927..6470919 100644 (file)
@@ -49,6 +49,7 @@ public final class AppPickerActivity extends ListActivity {
     if (position >= 0 && position < labelsPackages.size()) {
       String url = "market://search?q=pname:" + labelsPackages.get(position)[1];
       Intent intent = new Intent();
+      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);      
       intent.putExtra(Browser.BookmarkColumns.URL, url);
       setResult(RESULT_OK, intent);
     } else {
index b734580..ce5917d 100644 (file)
@@ -70,6 +70,7 @@ public final class BookmarkPickerActivity extends ListActivity {
   protected void onListItemClick(ListView l, View view, int position, long id) {
     if (cursor.moveToPosition(position)) {
       Intent intent = new Intent();
+      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
       intent.putExtra(Browser.BookmarkColumns.TITLE, cursor.getString(TITLE_COLUMN));
       intent.putExtra(Browser.BookmarkColumns.URL, cursor.getString(URL_COLUMN));
       setResult(RESULT_OK, intent);
index c1889ec..8d83529 100755 (executable)
@@ -65,14 +65,16 @@ public final class ShareActivity extends Activity {
 
   private final Button.OnClickListener contactListener = new Button.OnClickListener() {
     public void onClick(View v) {
-      startActivityForResult(new Intent(Intent.ACTION_PICK, Contacts.People.CONTENT_URI),
-          PICK_CONTACT);
+      Intent intent = new Intent(Intent.ACTION_PICK, Contacts.People.CONTENT_URI);
+      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
+      startActivityForResult(intent, PICK_CONTACT);
     }
   };
 
   private final Button.OnClickListener bookmarkListener = new Button.OnClickListener() {
     public void onClick(View v) {
       Intent intent = new Intent(Intent.ACTION_PICK);
+      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
       intent.setClassName(ShareActivity.this, BookmarkPickerActivity.class.getName());
       startActivityForResult(intent, PICK_BOOKMARK);
     }
@@ -81,6 +83,7 @@ public final class ShareActivity extends Activity {
   private final Button.OnClickListener appListener = new Button.OnClickListener() {
     public void onClick(View v) {
       Intent intent = new Intent(Intent.ACTION_PICK);
+      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
       intent.setClassName(ShareActivity.this, AppPickerActivity.class.getName());
       startActivityForResult(intent, PICK_APP);
     }
@@ -92,6 +95,7 @@ public final class ShareActivity extends Activity {
       // Should always be true, because we grey out the clipboard button in onResume() if it's empty
       if (clipboard.hasText()) {
         Intent intent = new Intent(Intents.Encode.ACTION);
+        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
         intent.putExtra(Intents.Encode.TYPE, Contents.Type.TEXT);
         intent.putExtra(Intents.Encode.DATA, clipboard.getText());
         intent.putExtra(Intents.Encode.FORMAT, Contents.Format.QR_CODE);
@@ -144,6 +148,7 @@ public final class ShareActivity extends Activity {
 
   private void showTextAsBarcode(String text) {
     Intent intent = new Intent(Intents.Encode.ACTION);
+    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
     intent.putExtra(Intents.Encode.TYPE, Contents.Type.TEXT);
     intent.putExtra(Intents.Encode.DATA, text);
     intent.putExtra(Intents.Encode.FORMAT, Contents.Format.QR_CODE);
@@ -212,6 +217,7 @@ public final class ShareActivity extends Activity {
       }
 
       Intent intent = new Intent(Intents.Encode.ACTION);
+      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);      
       intent.putExtra(Intents.Encode.TYPE, Contents.Type.CONTACT);
       intent.putExtra(Intents.Encode.DATA, bundle);
       intent.putExtra(Intents.Encode.FORMAT, Contents.Format.QR_CODE);