Advertisement
vyoumans

ANDROID QRScan crashes when returns to Fragment

Dec 26th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.67 KB | None | 0 0
  1. // The problem that I am having is when I call a QRCODE scan from a fragment, the app crashes when it returns to the fragment. It scans perfectly well, but I think the problem lies at:
  2. //**************** this is where I think the problem is....
  3. @Override
  4. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  5. have this same code running from another app with an activity and only two fragments.
  6. I would try to run this in an emulator, but Emulators don't have cams.
  7. //==============================================================================
  8.  
  9.  
  10.  
  11. package com.techlatin.loge;
  12.  
  13. import android.content.Context;
  14. import android.content.Intent;
  15. import android.graphics.Color;
  16. import android.location.Location;
  17. import android.location.LocationListener;
  18. import android.location.LocationManager;
  19. import android.support.v7.app.ActionBarActivity;
  20. import android.support.v7.app.ActionBar;
  21. import android.support.v4.app.Fragment;
  22. import android.os.Bundle;
  23. import android.view.LayoutInflater;
  24. import android.view.Menu;
  25. import android.view.MenuItem;
  26. import android.view.View;
  27. import android.view.ViewGroup;
  28. import android.os.Build;
  29. import android.widget.Button;
  30. import android.widget.TextView;
  31.  
  32. public class ZZE_NewLocations extends ActionBarActivity {
  33.  
  34. String session_id;
  35. String session_name;
  36.  
  37. String Lat;
  38. String Lng;
  39. String zzBINIDQR;
  40.  
  41. String ErrorText;
  42. Boolean thereWasAnError = false;
  43.  
  44.  
  45.  
  46. @Override
  47. protected void onCreate(Bundle savedInstanceState) {
  48. super.onCreate(savedInstanceState);
  49. setContentView(R.layout.activity_zze__new_locations);
  50.  
  51. if (savedInstanceState == null) {
  52. getSupportFragmentManager().beginTransaction()
  53. .add(R.id.container, new PlaceholderFragment())
  54. .commit();
  55. }
  56. }
  57.  
  58.  
  59. @Override
  60. public boolean onCreateOptionsMenu(Menu menu) {
  61.  
  62. // Inflate the menu; this adds items to the action bar if it is present.
  63. getMenuInflater().inflate(R.menu.zze__new_locations, menu);
  64. return true;
  65. }
  66.  
  67. @Override
  68. public boolean onOptionsItemSelected(MenuItem item) {
  69. // Handle action bar item clicks here. The action bar will
  70. // automatically handle clicks on the Home/Up button, so long
  71. // as you specify a parent activity in AndroidManifest.xml.
  72. int id = item.getItemId();
  73. if (id == R.id.action_settings) {
  74. return true;
  75. }
  76. return super.onOptionsItemSelected(item);
  77. }
  78.  
  79. /**
  80. * A placeholder fragment containing a simple view.
  81. */
  82. public static class PlaceholderFragment extends Fragment {
  83.  
  84. public PlaceholderFragment() {
  85. }
  86.  
  87. @Override
  88. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  89. Bundle savedInstanceState) {
  90. View rootView = inflater.inflate(R.layout.fragment_zze__new_locations, container, false);
  91. return rootView;
  92. }
  93. }
  94.  
  95. //==========================================================
  96.  
  97. private boolean resumeHasRun = false;
  98. @Override
  99. protected void onResume(){
  100.  
  101. //Button btnst01 = (Button) findViewById(R.id.btnStep1_submit);
  102. //btnst01.setEnabled(false);
  103.  
  104. super.onResume();
  105. if (!resumeHasRun){
  106. resumeHasRun = true;
  107. //return;
  108. }
  109. // get the session stuff here
  110.  
  111. Bundle extras = getIntent().getExtras();
  112. if (extras != null) {
  113. session_id = extras.getString("session_id");
  114. session_name = extras.getString("session_name");
  115.  
  116. final TextView xxSESSION_NAME = (TextView) findViewById(R.id.tvSESSION_NAME01);
  117. xxSESSION_NAME.setText(session_name);
  118.  
  119. final TextView xxSESSION_ID = (TextView) findViewById(R.id.tvSESSION_ICD01);
  120. xxSESSION_ID.setText(session_id);
  121.  
  122. }
  123.  
  124. Do_WHATABOUT_ZZE();
  125.  
  126. }
  127.  
  128. private void Do_WHATABOUT_ZZE(){
  129. // will explain what this screen is about
  130. TextView tv_zze_WhatAbout = (TextView) findViewById(R.id.tv_ZZE_WHAT_ABOUT);
  131. tv_zze_WhatAbout.setText("This screen is for NEW deployments of Existing and New Assets. You should use this screen only ONCE per Asset.");
  132. }
  133.  
  134.  
  135.  
  136. //================================================================
  137. //QRCode Reading
  138.  
  139.  
  140. public void btnZZZB_STEP01_SCAN01_click (View view){
  141. Intent intent = new Intent("com.google.zxing.client.android.SCAN");
  142. //intent.putExtra("SCAN_MODE", "PRODUCT_MODE");//for Qr code, its "QR_CODE_MODE" instead of "PRODUCT_MODE"
  143. intent.putExtra("SCAN_MODE", "QR_CODE_MODE");//for Qr code, its "QR_CODE_MODE" instead of "PRODUCT_MODE"
  144. intent.putExtra("SAVE_HISTORY", false);//this stops saving ur barcode in barcode scanner app's history
  145. startActivityForResult(intent, 0);
  146. }
  147.  
  148.  
  149. //**************** this is where I think the problem is....
  150. @Override
  151. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  152. super.onActivityResult(requestCode, resultCode, data);
  153. if (requestCode == 0) {
  154. if (resultCode == RESULT_OK) {
  155. //String contents = data.getStringExtra("SCAN_RESULT"); //this is the result
  156.  
  157. // zzBINIDQR = data.getStringExtra("SCAN_RESULT");
  158.  
  159.  
  160. // TextView tvtest000 = (TextView) findViewById(R.id.tvBINID_QR);
  161. // tvtest000.setText(BINID_QR);
  162. // tvtest000.setBackgroundColor(Color.GREEN);
  163.  
  164. //BINID_QR = contents;
  165.  
  166. //Button btnst01a = (Button) findViewById(R.id.btnStep1_submit);
  167. //btnst01.setEnabled(true);
  168.  
  169. }
  170. else if (resultCode == RESULT_CANCELED) {
  171. // Handle cancel
  172. //Button btnst01 = (Button) findViewById(R.id.btnStep1_submit);
  173. //btnst01.setEnabled(false);
  174.  
  175. zzBINIDQR = "--- no result ---";
  176.  
  177.  
  178. // TextView tvtest000 = (TextView) findViewById(R.id.tvBINID_QR);
  179. // tvtest000.setText(BINID_QR);
  180. // tvtest000.setBackgroundColor(Color.RED);
  181.  
  182. }
  183. }
  184. }
  185.  
  186.  
  187.  
  188. //======================== FRAGMENTS ===============================
  189. public void btnClick_zze_01__loc_id(View view){
  190.  
  191. setContentView(R.layout.fragment_zze_01__loc_id);
  192.  
  193. }
  194.  
  195.  
  196.  
  197.  
  198. //======================== FRAGMENTS ===============================
  199. public void btnClick_zze_09__return(View view){
  200.  
  201. setContentView(R.layout.fragment_zze__new_locations);
  202.  
  203. }
  204.  
  205.  
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement