I have the following issue…I’m implementing a QR code game in my android application…that is done by launching this intent:
Intent intent = new Intent(
"com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
In other words I start the Barcode Scanner application.
Want I want to do is launch this application and even if the user starts scanning a barcode or not the application will close automatically after two minutes.
Of course if the user doesn’t close it mean time.
I tried implementing an AsyncTask thread like this:
in onCreate()
initTask=new InitTask();
initTask.execute();
outside of onCreate()
private class InitTask extends AsyncTask<Void,Void,Void>{
protected Void doInBackground(Void...unused){
new Runnable() {
@Override
public void run() {
try {
Thread.sleep(20000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
Intent intent = new Intent(
"com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
}.run();
this.cancel(true);
return null;
}
}
outside of onCreate()
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
//..........
}
The problem is that the app gets opened but it doesn’t close automatically after 2 minutes.
Does someone know how could I achieve that?
Update
Activity Result