小编Rom*_*ain的帖子

Android意图过滤器重启活动?

我正在开发一个连接到平板电脑时与 USB 设备通信的应用程序。为了避免用户接受 android 访问设备,我设置了一个意图过滤器:

<intent-filter>
            <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
            <action android:name="android.hardware.usb.action.USB" />
        </intent-filter>
        <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/usb_device_filter" />
Run Code Online (Sandbox Code Playgroud)

我的问题是,有了这个意图过滤器,每次我插入设备并启动另一个活动时,都会调用“onCreate”方法,如果没有意图过滤器,它只会被调用一次。这是“onCreate”方法:

@Override   
protected void onCreate(Bundle savedInstanceState) {    
    try {   
        super.onCreate(savedInstanceState);         
        setContentView(R.layout.activity_msp430_hid);               //define activity layout
        setVersionToTitle();    
        btnSend = (Button) findViewById(R.id.btnSend);      //Send button
        btnSend.setOnClickListener(this);                   //Listener for Send Button
        btnSend.setEnabled(true);
        btnSelectHIDDevice = (Button) findViewById(R.id.btnSelectHIDDevice);    //Select HID Device button
        btnSelectHIDDevice.setOnClickListener(this);        //Listener for Select HID Device button
        btnClear = (Button) findViewById(R.id.btnClear);    //Clear button
        btnClear.setOnClickListener(this);                  //Listener for Clear button
        edtxtHidInput = (EditText) findViewById(R.id.edtxtHidInput);    //User editable text area for sending …
Run Code Online (Sandbox Code Playgroud)

usb android intentfilter

6
推荐指数
1
解决办法
1730
查看次数

标签 统计

android ×1

intentfilter ×1

usb ×1