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 7636817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:46:50+00:00 2026-05-31T07:46:50+00:00

Recently am being playing around with qr code generation, and after alot of google

  • 0

Recently am being playing around with qr code generation, and after alot of google and help from stack overflow members i was successfully able to generated it, using google API.

but when i click “back” button in the emulator and when i again click theapplication the qr code image disappears??

how to make it stay permanent until i click the “generate” button again for a new Qr image??

here is the code for my question’s answer providers and those who are struggling in generation of qr images

    package com.test2;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class Test2Activity extends Activity {


     ImageView QRCode;
     TextView MySite;
     EditText text,text1; 
     Button genarate;
     String textbox,textbox2;

       /** Called when the activity is first created. */
       @Override
       public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.main);

           QRCode = (ImageView)findViewById(R.id.qrimage);
           MySite = (TextView)findViewById(R.id.mysite);

           genarate=(Button)findViewById(R.id.genarate);
           genarate.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                text=(EditText)findViewById(R.id.text);
                text1=(EditText)findViewById(R.id.text1);
                textbox=text.getText().toString();
                textbox2=text1.getText().toString();
                Bitmap bm = loadQRCode();
                    if(bm == null){
                    Toast.makeText(Test2Activity.this,
                      "Problem in loading QR Code1",
                      Toast.LENGTH_LONG).show();
                   }else{
                    QRCode.setImageBitmap(bm);
                   }
            }
                    Bitmap loadQRCode(){
                    Bitmap bmQR = null;
                    InputStream inputStream = null;

                    try {
                   inputStream = OpenHttpConnection("http://chart.apis.google.com/chart?chs=400x400&cht=qr&chl="+ textbox +"--->"+ textbox2);
                   bmQR = BitmapFactory.decodeStream(inputStream);
                   inputStream.close();
                  } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                  }
                    return bmQR;
                   }

                   private InputStream OpenHttpConnection(String strURL) throws IOException{
                    InputStream is = null;
                    URL url = new URL(strURL);
                    URLConnection urlConnection = url.openConnection();

                    try{
                     HttpURLConnection httpConn = (HttpURLConnection)urlConnection;
                     httpConn.setRequestMethod("GET");
                     httpConn.connect();

                     if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                      is = httpConn.getInputStream(); 
                     }
                     }catch (Exception ex){
                     }

                    return is; 
                 }  
        });
       }
    }

xml code for this activity

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scrollView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >
<TextView 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="@string/hello"
   />

<EditText
    android:id="@+id/text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

<EditText
    android:id="@+id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <requestFocus />
</EditText>

<Button
    android:id="@+id/genarate"
    android:layout_width="97dp"
    android:layout_height="wrap_content"
    android:text="genarate" />

<ImageView 
   android:id="@+id/qrimage"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:saveEnabled="true" android:visibility="visible"/>

<TextView 
   android:id="@+id/mysite"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   />
</LinearLayout>

    </ScrollView>
  • 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-31T07:46:51+00:00Added an answer on May 31, 2026 at 7:46 am

    You can save the generated image as a Base64 string in your SharedPreferences.

    To encode the image do something like: Base64.encode(image, Base64.DEFAULT).

    To store and retrieve values from your SharedPreferences you can use in your Activity:

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);   
    
    //Save String
    preferences.edit().putString("image64", imageData).commit();
    
    //Get String
    String imageBase64 = preferences.getString("image64", null);
                                                           ^----- Default value
    if(imageBase64 == null)
        Log.d("LOG", "No image stored in the SharedPreferences");
    
    //Create a bitmap from the base64 data
    byte[] decodedString = Base64.decode(imageBase64, Base64.DEFAULT);
    Bitmap bm = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started playing around with Apache camel recently. So being the experimental type
Recently, after being very tired, I wrote the following code: GLfloat* array = new
I recently switched out log4net logging from using config files to being set up
We've recently hit a snag where a trademark symbol is being copied from one
Recently I've migrated to Arch Linux, after ~4 years being loyal to Ubuntu. Everything
I've been playing around with Knockout recently and I'm trying to replace a $().change
I have recently started playing around with iOS development and have got most of
I've been playing around with OpenGL for a full week or equivalent. After 2D
I've been playing with the recently released jQueryGannt plugin / application from here and
I recently recovered from not being able to test on my device in Xcode.

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.