Hei! In my android app I have a button that starts the app Barcode Scanner. I want to stop this app after 2 minutes, for example. How can I do this?
This is my code :
qrgame = (Button) findViewById(R.id.qrgame);
qrgame.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
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);
}
});
you can finish your activity as you can start your activity using
you need to pass the same requestcode to this method
for delay time you can you Thread, Timer etc.
Or you can close your opened activity just implement Timer, thread which will hold you 2 min or as per your requirement then call
You can create an
asyncTask
that you execute in theonCreate
of your app. And in theAsyncTask
you write aAfter that you can stop your app.
I had a similar requirement, put whatever you wish to be run in some method and call the method start and stop as such.
on you on create method put this code
do not forget your to import the Thread or if you use elipse just CRTL+SHIFT+O