设备插入卸载监听优化

chengzhenyu 6 年之前
父节点
当前提交
19896cf9d9
共有 2 个文件被更改,包括 10 次插入4 次删除
  1. 1 0
      app/src/main/AndroidManifest.xml
  2. 9 4
      app/src/main/java/com/ptplib/usbcamera/test/MyTestActivity.java

+ 1 - 0
app/src/main/AndroidManifest.xml

@@ -17,6 +17,7 @@
17 17
         </activity>
18 18
         <activity
19 19
             android:name="com.ptplib.usbcamera.test.MyTestActivity"
20
+            android:launchMode="singleTask"
20 21
             android:screenOrientation="portrait">
21 22
             <intent-filter>
22 23
                 <action android:name="android.intent.action.MAIN" />

+ 9 - 4
app/src/main/java/com/ptplib/usbcamera/test/MyTestActivity.java

@@ -70,19 +70,24 @@ public class MyTestActivity extends Activity {
70 70
     }
71 71
 
72 72
     @Override
73
-    protected void onResume() {
74
-        super.onResume();
73
+    protected void onStart() {
74
+        super.onStart();
75 75
         registerUSBReceiver();
76 76
         initDevice (searchDevice ());
77 77
     }
78 78
 
79 79
     @Override
80
-    protected void onPause() {
81
-        super.onPause();
80
+    protected void onStop() {
81
+        super.onStop();
82 82
         unregisterReceiver(mUsbReceiver);
83 83
         detachDevice();
84 84
     }
85 85
 
86
+    @Override
87
+    protected void onNewIntent(Intent intent) {
88
+        super.onNewIntent(intent);
89
+    }
90
+
86 91
     BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
87 92
         public void onReceive(Context context, Intent intent) {
88 93
             String action = intent.getAction();