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

  • Home
  • SEARCH
  • 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 7490113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:33:10+00:00 2026-05-29T15:33:10+00:00

I am programming on an android app, and I have a program with a

  • 0

I am programming on an android app, and I have a program with a qr scanner. When the scanner detects a scan something happens. My problem is that I have more than one qr code, and I need the program to recognize which qr code is being scanned.
In my code I have a string “contents” that I set to be equal “SCAN_RESULT” which is different from each qr code.
I see the result by printing in logCat and I have also made a textView to be the same as contents. In both cases the “SCAN_RESULT” is “Scanextra1” for the first qr code.
I then say: if(contents == “Scanextra1”){ something should happen}. It doesn’t though.
Can anyone help me please?

The code where I am having a problem looks like this:

       if (resultCode1 == RESULT_OK) {
         contents = intent.getStringExtra("SCAN_RESULT");
         String format = intent.getStringExtra("SCAN_RESULT_FORMAT");

         int QR = 0;
         Log.v(contents, "QR value" + QR);

         proeve.setText(contents);   
         //String contents2 = proeve.getText().toString(); 

        if (contents == "Scanextra1"){...

The entire code for the activity looks like this:

  package your.choko.namespace;

  import android.app.Activity;
  import android.content.Intent;
  import android.content.SharedPreferences;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuInflater;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.TextView;
  import android.widget.Toast;
  import android.util.Log;

  public class ScanExtra extends Activity {

    String contents;

    public static final String PREFS_NAME = "MyPrefsFile";

boolean extra1, extra2;

public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.scanextra);

     SharedPreferences settings = getSharedPreferences("MyPrefsFile", 0);
           extra1 = settings.getBoolean("fact1", false);
       extra2 = settings.getBoolean("fact2", false);

Button scan = (Button) findViewById(R.id.buttonscanextra);
 scan.setOnClickListener(new OnClickListener() {

 static final int QR_ACTIVITY = 0; 
 public void onClick(View v) {
 Intent intent = new Intent("com.google.zxing.client.android.SCAN");
 intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
 startActivityForResult(intent, QR_ACTIVITY);
 } 
});
 } 

/** Called when the activity is first created. */
 @Override
 public void onPause() {
 super.onPause();

 } 

@Override
 public void onStop() {
 super.onStop();
 } 

public void onActivityResult(int requestCode, int resultCode1, Intent intent) {

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

    if (requestCode == 0) {

       if (resultCode1 == RESULT_OK) {
         contents = intent.getStringExtra("SCAN_RESULT");
         String format = intent.getStringExtra("SCAN_RESULT_FORMAT");

         int QR = 0;
         Log.v(contents, "QR value" + QR);

         proeve.setText(contents);   

        if (contents == "Scanextra1"){

      //WHAT HAPPENS ON SCAN 1          
        SharedPreferences settings = getSharedPreferences("MyPrefsFile",0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putBoolean("fact1", true);           
            editor.commit();

        Toast toast = Toast.makeText(ScanExtra.this, contents, 9000);
        toast.show();
      startActivity(new Intent(ScanExtra.this, ScanExtraResultat.class));   
     }
    }
    }
    }

}

  • 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-29T15:33:10+00:00Added an answer on May 29, 2026 at 3:33 pm

    You shouldn’t use == for string comparison. Use equals() instead:

    if (contents.equals("Scanextra1")) {
        ...
    }
    

    When you use ==, you check whether the two things are exactly the same object. When you use equals(), you check whether the contents of the two strings are the same.

    See also:

    • Java String comparison. The difference between == and equals()
    • Java String.equals versus ==
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm abit new to programming Android App's, however I have come across a problem,
I have read that it will allow creating an Android app without (much) programming
The android-app I'm programming is going to have a database of products, say 150-250
I am not that experienced with Java/Android programming. I have an array of floats
I have been programming an Android App for a while and we want to
again i have got a problem with socket programming in Android. My Problem is
I am new to Eclipse and Android programming in general but I have been
I've been programming Android in Eclipse for about a year now and I have
I'm really new in Android programming, so I have a simple question getting a
I'm developing an iPhone (and later Android) app that has real-time features, i.e. when

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.