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");
}
}