Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6555863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:52:19+00:00 2026-05-25T12:52:19+00:00

I have the following issue…I’m implementing a QR code game in my android application…that

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:52:19+00:00Added an answer on May 25, 2026 at 12:52 pm

    Update

    private class InitTask extends AsyncTask<Void,Void,Void>{
    @Override
    protected void onPreExecute()
    {
       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, 1515);
    }
    protected Void doInBackground(Void...unused){
    
    try
    {
           Thread.sleep(20000);
    }
    catch(Exception e)
    {
        System.out.println(e);
    }
    return null;
    
    }
    @Override
    protected void onPostExecute(Void result) 
    {
    
       finishActivity(1515);
    
    }
    
    
    }
    

    Activity Result

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
                if (requestCode == 1515) {
                    if (resultCode == RESULT_OK) {
                        String contents = intent.getStringExtra("SCAN_RESULT");
                        String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
                        System.out.println("it is ok");
                        // Handle successful scan
                    } else if (resultCode == RESULT_CANCELED) {
                        // Handle cancel
                        System.out.println("it is cancel");
                    }
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im having the following issue i have this post action that is called by
I'm trying to adress the following issue: I have a server side .net application
I have the following issue. My customer paid for the product that costs 13,60
I have the following issue: when a stored proc is called from my application,
I have the following issue: I have a MVC application, in some action of
I came across the following issue: I have this model public class Region {
I have the following issue. I have deployed a smart client application to several
I have the following issue whith this very simple task. I want to create
I have following issue: I'm introducing new feature into application (run as Windows Service)
I have the following issue. I have two classes that manipulate information but they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.