0

I have such a complicated problem to solve alone.

I have a sample program that just tells me that the name of the device that connect to the USB port on the tablet, the device I use is the card reader.

Every time I turn the player on or off, my activity is finished and then restarts, I wonder if this is possible avoid restarting the activity.

In other words, my activity is finished and soon one is to open another.

I used android: launchMode = "SingleInstance" but not resolved

The Android version is 2.3.4.

My code:

public class MainActivity extends Activity {

    @SuppressLint("NewApi")
    @TargetApi(Build.VERSION_CODES.GINGERBREAD)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView txtView = (TextView)findViewById(R.id.textView1);

        int[] input = InputDevice.getDeviceIds();

        if(input.length == 5) {
            InputDevice A = InputDevice.getDevice(input[4]);
            txtView.setText(A.getName());
        }
        else {
            txtView.setText("Not Device");
        }
    }
Klettseb
  • 129
  • 10
Blade199
  • 15
  • 7
  • This is by design, since connecting a USB device is considered to be a configuration change. Your code should be designed to deal with it, not to avoid it. Save your values in onPause() and reload them in onResume(). There are lots of examples for doing that here and available with a Google search for "activity life cycle". – Simon Feb 26 '14 at 13:31
  • Check this answer: [Hope it helps you][1] [1]: http://stackoverflow.com/questions/6981736/android-3-1-usb-host-broadcastreceiver-does-not-receive-usb-device-attached – Dan Cuc Feb 26 '14 at 13:36
  • @Simon Thanks, Your suggestion is the most ideal, since it is not possible to avoid this problem. – Blade199 Feb 27 '14 at 03:09

0 Answers0