How can I find context and start a new Activity from Android firebase ML-Kit BarcodeScannerProcessor...












1














I am using the quickstart-android code provided by google but after many attempts I cam unable to find a context that is not returning null. The BarcodeScannerProcessor is not itself an Activity, so I have attempted to create an instance of the LivePreviewActivity and use that as the context in the intent, but it's null.



The goal is to once a valid barcode is recognized I want to open a new activity that allows a user to verify value and on the push of a button call a webservice to post the barcode to a database via API. I am having a hard time finding a valid context and the app is crashing when it trys to execute the Intent.



Starting at line 97-107:



https://github.com/jamiekeefer/quickstart-android/blob/master/mlkit/app/src/main/java/com/google/firebase/samples/apps/mlkit/java/barcodescanning/BarcodeScanningProcessor.java



        for (int i = 0; i < barcodes.size(); ++i) {
FirebaseVisionBarcode barcode = barcodes.get(i);
BarcodeGraphic barcodeGraphic = new BarcodeGraphic(graphicOverlay, barcode);
graphicOverlay.add(barcodeGraphic);

System.out.println(barcode.getRawValue());

if (!barcode.getRawValue().equals("") ) {

System.out.println("Got the number:" + barcode.getRawValue() + " Context: " + mContext); //OLD SCHOOL DEBUG OUTPUT

//enter code to start activity

Intent intent = new Intent(mContext, SendScannedBarcode.class);
String message = scannedBarcode;
intent.putExtra(EXTRA_MESSAGE, message);
mContext.startActivity(intent);
}


}


You can back up in the repo to see the instance of the LivePreviewActivity where I trying to get context.



I have tried a number of things and read about Context, Views and Activities and basically have completely confused myself. The only tuts I can find are using Kotlin, which is not helping clarify things.



I appreacite any help in indentifying or contruting a valid Intent from this Context. Thank you.










share|improve this question


















  • 1




    Jamie, did my answer help you?
    – Ishaan
    Nov 23 at 4:19










  • Ishaan, I am just getting back in front of my computer. I have been travelling and been unable to test until now. I will let you know asap.
    – Jamie Keefer
    Nov 23 at 19:56










  • Ishaan, SUCCESS! Finally got to a place with good enough wifi to update my android and build. Worked like a charm!
    – Jamie Keefer
    Nov 24 at 21:25










  • Working Source here: github.com/jamiekeefer/quickstart-android
    – Jamie Keefer
    Nov 24 at 21:36










  • You're welcome! I'm glad that after 4 days, you finally got to test it.
    – Ishaan
    Nov 24 at 21:41
















1














I am using the quickstart-android code provided by google but after many attempts I cam unable to find a context that is not returning null. The BarcodeScannerProcessor is not itself an Activity, so I have attempted to create an instance of the LivePreviewActivity and use that as the context in the intent, but it's null.



The goal is to once a valid barcode is recognized I want to open a new activity that allows a user to verify value and on the push of a button call a webservice to post the barcode to a database via API. I am having a hard time finding a valid context and the app is crashing when it trys to execute the Intent.



Starting at line 97-107:



https://github.com/jamiekeefer/quickstart-android/blob/master/mlkit/app/src/main/java/com/google/firebase/samples/apps/mlkit/java/barcodescanning/BarcodeScanningProcessor.java



        for (int i = 0; i < barcodes.size(); ++i) {
FirebaseVisionBarcode barcode = barcodes.get(i);
BarcodeGraphic barcodeGraphic = new BarcodeGraphic(graphicOverlay, barcode);
graphicOverlay.add(barcodeGraphic);

System.out.println(barcode.getRawValue());

if (!barcode.getRawValue().equals("") ) {

System.out.println("Got the number:" + barcode.getRawValue() + " Context: " + mContext); //OLD SCHOOL DEBUG OUTPUT

//enter code to start activity

Intent intent = new Intent(mContext, SendScannedBarcode.class);
String message = scannedBarcode;
intent.putExtra(EXTRA_MESSAGE, message);
mContext.startActivity(intent);
}


}


You can back up in the repo to see the instance of the LivePreviewActivity where I trying to get context.



I have tried a number of things and read about Context, Views and Activities and basically have completely confused myself. The only tuts I can find are using Kotlin, which is not helping clarify things.



I appreacite any help in indentifying or contruting a valid Intent from this Context. Thank you.










share|improve this question


















  • 1




    Jamie, did my answer help you?
    – Ishaan
    Nov 23 at 4:19










  • Ishaan, I am just getting back in front of my computer. I have been travelling and been unable to test until now. I will let you know asap.
    – Jamie Keefer
    Nov 23 at 19:56










  • Ishaan, SUCCESS! Finally got to a place with good enough wifi to update my android and build. Worked like a charm!
    – Jamie Keefer
    Nov 24 at 21:25










  • Working Source here: github.com/jamiekeefer/quickstart-android
    – Jamie Keefer
    Nov 24 at 21:36










  • You're welcome! I'm glad that after 4 days, you finally got to test it.
    – Ishaan
    Nov 24 at 21:41














1












1








1


1





I am using the quickstart-android code provided by google but after many attempts I cam unable to find a context that is not returning null. The BarcodeScannerProcessor is not itself an Activity, so I have attempted to create an instance of the LivePreviewActivity and use that as the context in the intent, but it's null.



The goal is to once a valid barcode is recognized I want to open a new activity that allows a user to verify value and on the push of a button call a webservice to post the barcode to a database via API. I am having a hard time finding a valid context and the app is crashing when it trys to execute the Intent.



Starting at line 97-107:



https://github.com/jamiekeefer/quickstart-android/blob/master/mlkit/app/src/main/java/com/google/firebase/samples/apps/mlkit/java/barcodescanning/BarcodeScanningProcessor.java



        for (int i = 0; i < barcodes.size(); ++i) {
FirebaseVisionBarcode barcode = barcodes.get(i);
BarcodeGraphic barcodeGraphic = new BarcodeGraphic(graphicOverlay, barcode);
graphicOverlay.add(barcodeGraphic);

System.out.println(barcode.getRawValue());

if (!barcode.getRawValue().equals("") ) {

System.out.println("Got the number:" + barcode.getRawValue() + " Context: " + mContext); //OLD SCHOOL DEBUG OUTPUT

//enter code to start activity

Intent intent = new Intent(mContext, SendScannedBarcode.class);
String message = scannedBarcode;
intent.putExtra(EXTRA_MESSAGE, message);
mContext.startActivity(intent);
}


}


You can back up in the repo to see the instance of the LivePreviewActivity where I trying to get context.



I have tried a number of things and read about Context, Views and Activities and basically have completely confused myself. The only tuts I can find are using Kotlin, which is not helping clarify things.



I appreacite any help in indentifying or contruting a valid Intent from this Context. Thank you.










share|improve this question













I am using the quickstart-android code provided by google but after many attempts I cam unable to find a context that is not returning null. The BarcodeScannerProcessor is not itself an Activity, so I have attempted to create an instance of the LivePreviewActivity and use that as the context in the intent, but it's null.



The goal is to once a valid barcode is recognized I want to open a new activity that allows a user to verify value and on the push of a button call a webservice to post the barcode to a database via API. I am having a hard time finding a valid context and the app is crashing when it trys to execute the Intent.



Starting at line 97-107:



https://github.com/jamiekeefer/quickstart-android/blob/master/mlkit/app/src/main/java/com/google/firebase/samples/apps/mlkit/java/barcodescanning/BarcodeScanningProcessor.java



        for (int i = 0; i < barcodes.size(); ++i) {
FirebaseVisionBarcode barcode = barcodes.get(i);
BarcodeGraphic barcodeGraphic = new BarcodeGraphic(graphicOverlay, barcode);
graphicOverlay.add(barcodeGraphic);

System.out.println(barcode.getRawValue());

if (!barcode.getRawValue().equals("") ) {

System.out.println("Got the number:" + barcode.getRawValue() + " Context: " + mContext); //OLD SCHOOL DEBUG OUTPUT

//enter code to start activity

Intent intent = new Intent(mContext, SendScannedBarcode.class);
String message = scannedBarcode;
intent.putExtra(EXTRA_MESSAGE, message);
mContext.startActivity(intent);
}


}


You can back up in the repo to see the instance of the LivePreviewActivity where I trying to get context.



I have tried a number of things and read about Context, Views and Activities and basically have completely confused myself. The only tuts I can find are using Kotlin, which is not helping clarify things.



I appreacite any help in indentifying or contruting a valid Intent from this Context. Thank you.







java android firebase-mlkit






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 16:56









Jamie Keefer

206




206








  • 1




    Jamie, did my answer help you?
    – Ishaan
    Nov 23 at 4:19










  • Ishaan, I am just getting back in front of my computer. I have been travelling and been unable to test until now. I will let you know asap.
    – Jamie Keefer
    Nov 23 at 19:56










  • Ishaan, SUCCESS! Finally got to a place with good enough wifi to update my android and build. Worked like a charm!
    – Jamie Keefer
    Nov 24 at 21:25










  • Working Source here: github.com/jamiekeefer/quickstart-android
    – Jamie Keefer
    Nov 24 at 21:36










  • You're welcome! I'm glad that after 4 days, you finally got to test it.
    – Ishaan
    Nov 24 at 21:41














  • 1




    Jamie, did my answer help you?
    – Ishaan
    Nov 23 at 4:19










  • Ishaan, I am just getting back in front of my computer. I have been travelling and been unable to test until now. I will let you know asap.
    – Jamie Keefer
    Nov 23 at 19:56










  • Ishaan, SUCCESS! Finally got to a place with good enough wifi to update my android and build. Worked like a charm!
    – Jamie Keefer
    Nov 24 at 21:25










  • Working Source here: github.com/jamiekeefer/quickstart-android
    – Jamie Keefer
    Nov 24 at 21:36










  • You're welcome! I'm glad that after 4 days, you finally got to test it.
    – Ishaan
    Nov 24 at 21:41








1




1




Jamie, did my answer help you?
– Ishaan
Nov 23 at 4:19




Jamie, did my answer help you?
– Ishaan
Nov 23 at 4:19












Ishaan, I am just getting back in front of my computer. I have been travelling and been unable to test until now. I will let you know asap.
– Jamie Keefer
Nov 23 at 19:56




Ishaan, I am just getting back in front of my computer. I have been travelling and been unable to test until now. I will let you know asap.
– Jamie Keefer
Nov 23 at 19:56












Ishaan, SUCCESS! Finally got to a place with good enough wifi to update my android and build. Worked like a charm!
– Jamie Keefer
Nov 24 at 21:25




Ishaan, SUCCESS! Finally got to a place with good enough wifi to update my android and build. Worked like a charm!
– Jamie Keefer
Nov 24 at 21:25












Working Source here: github.com/jamiekeefer/quickstart-android
– Jamie Keefer
Nov 24 at 21:36




Working Source here: github.com/jamiekeefer/quickstart-android
– Jamie Keefer
Nov 24 at 21:36












You're welcome! I'm glad that after 4 days, you finally got to test it.
– Ishaan
Nov 24 at 21:41




You're welcome! I'm glad that after 4 days, you finally got to test it.
– Ishaan
Nov 24 at 21:41












3 Answers
3






active

oldest

votes


















1














So I am assuming that in your LivePreviewActivity you are creating an object of the class BarcodeScanningProcessor. What you can do is change the constructor in the BarcodeScanningProcessor class to accept a context and then you pass in your LivePreviewActivity's context.



This is what the code should look like:



In BarcodeScanningProcessor:



  public BarcodeScanningProcessor(Context context) {
// Note that if you know which format of barcode your app is dealing with, detection will be
// faster to specify the supported barcode formats one by one, e.g.
// new FirebaseVisionBarcodeDetectorOptions.Builder()
// .setBarcodeFormats(FirebaseVisionBarcode.FORMAT_QR_CODE)
// .build();
detector = FirebaseVision.getInstance().getVisionBarcodeDetector();
this.mContext = context;
}


Then in LivePreviewActivity:



In the particular case of your activity you would do:



  case BARCODE_DETECTION:
Log.i(TAG, "Using Barcode Detector Processor");
cameraSource.setMachineLearningFrameProcessor(new BarcodeScanningProcessor(getApplicationContext()));
break;


Or if you just wanted to create an object of the class you could do:
BarcodeScanningProcessor bsp = new BarcodeScanningProcessor(getApplicationContext());



This should now give your BarcodeScanningProcessor class the context of your activity. Now, in BarcodeScanningProcessor, mContext should not be null and will have the context of your activity. I hope this answers your question.






share|improve this answer























  • So I am assuming that in your LivePreviewActivity you are creating an object of the class BarcodeScanningProcessor. What you can do is change the constructor in the BarcodeScanningProcessor class to accept a context and then you pass in your LivePreviewActivity's context. --- AHH! Let me give that a try. That makes sense.
    – Jamie Keefer
    Nov 20 at 17:05










  • Yes. Try the code above. I am certain that it should work now that your BarcodeScanningProcessor class will have the context of your activity. If it works, please mark this answer as accepted so that those with similar problems can refer to it and get help as well.
    – Ishaan
    Nov 20 at 17:08










  • Ishaan, I can not thank you enough for answering so quickly. I will certainly mark as accepted once I can verify it works, which I am confident it will. My android studio install needs to patch so it may be a while, I am about get on an airplane and this network is not patching very well :/. I will be sure follow up. Thank you very much.
    – Jamie Keefer
    Nov 20 at 17:22










  • You are welcome. I hope that when you land and test it, it works. Make sure that you are on a good network though!
    – Ishaan
    Nov 20 at 23:21










  • Hello Jamie. Have you been able to test my solution? If it didn't work, just post the problem you got below.
    – Ishaan
    Nov 21 at 17:20



















1














try this create Application class



import android.app.Application;

public class MyApplication extends Application {
static MyApplication instance;

@Override
public void onCreate() {
super.onCreate();
instance=this;
}

public static MyApplication getInstance() {
return instance;
}
}


Register in manifest file



<application
..
android:name="com.yourpackage.MyApplication"
..>
.
.
.
</application>


start activity using this MyApplication.



Intent intent = new Intent(MyApplication.getInstance(), SendScannedBarcode.class);
String message = scannedBarcode;
intent.putExtra(EXTRA_MESSAGE, message);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MyApplication. getInstance().startActivity(intent);





share|improve this answer





















  • I will review this option as well. Thank you for the prompt reply.
    – Jamie Keefer
    Nov 20 at 17:23



















1














Another way of handling the issue is create new constructor of BarcodeScanningProcessor which takes interface call back and once processing is done pass back result to caller.



   public interface BarcodeUpdateListener {
@UiThread
void onBarcodeDetected(Barcode barcode);
}


private BarcodeUpdateListener callback;

public BarcodeScanningProcessor(BarcodeUpdateListener callback){
this.callback = callback;
detector = FirebaseVision.getInstance().getVisionBarcodeDetector();
}


Once you get the result pass result to caller



callback.onBarcodeDetected(<Barcode>)





share|improve this answer





















  • I will review this option as well. Thank you for the prompt reply.
    – Jamie Keefer
    Nov 20 at 17:23











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397880%2fhow-can-i-find-context-and-start-a-new-activity-from-android-firebase-ml-kit-bar%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














So I am assuming that in your LivePreviewActivity you are creating an object of the class BarcodeScanningProcessor. What you can do is change the constructor in the BarcodeScanningProcessor class to accept a context and then you pass in your LivePreviewActivity's context.



This is what the code should look like:



In BarcodeScanningProcessor:



  public BarcodeScanningProcessor(Context context) {
// Note that if you know which format of barcode your app is dealing with, detection will be
// faster to specify the supported barcode formats one by one, e.g.
// new FirebaseVisionBarcodeDetectorOptions.Builder()
// .setBarcodeFormats(FirebaseVisionBarcode.FORMAT_QR_CODE)
// .build();
detector = FirebaseVision.getInstance().getVisionBarcodeDetector();
this.mContext = context;
}


Then in LivePreviewActivity:



In the particular case of your activity you would do:



  case BARCODE_DETECTION:
Log.i(TAG, "Using Barcode Detector Processor");
cameraSource.setMachineLearningFrameProcessor(new BarcodeScanningProcessor(getApplicationContext()));
break;


Or if you just wanted to create an object of the class you could do:
BarcodeScanningProcessor bsp = new BarcodeScanningProcessor(getApplicationContext());



This should now give your BarcodeScanningProcessor class the context of your activity. Now, in BarcodeScanningProcessor, mContext should not be null and will have the context of your activity. I hope this answers your question.






share|improve this answer























  • So I am assuming that in your LivePreviewActivity you are creating an object of the class BarcodeScanningProcessor. What you can do is change the constructor in the BarcodeScanningProcessor class to accept a context and then you pass in your LivePreviewActivity's context. --- AHH! Let me give that a try. That makes sense.
    – Jamie Keefer
    Nov 20 at 17:05










  • Yes. Try the code above. I am certain that it should work now that your BarcodeScanningProcessor class will have the context of your activity. If it works, please mark this answer as accepted so that those with similar problems can refer to it and get help as well.
    – Ishaan
    Nov 20 at 17:08










  • Ishaan, I can not thank you enough for answering so quickly. I will certainly mark as accepted once I can verify it works, which I am confident it will. My android studio install needs to patch so it may be a while, I am about get on an airplane and this network is not patching very well :/. I will be sure follow up. Thank you very much.
    – Jamie Keefer
    Nov 20 at 17:22










  • You are welcome. I hope that when you land and test it, it works. Make sure that you are on a good network though!
    – Ishaan
    Nov 20 at 23:21










  • Hello Jamie. Have you been able to test my solution? If it didn't work, just post the problem you got below.
    – Ishaan
    Nov 21 at 17:20
















1














So I am assuming that in your LivePreviewActivity you are creating an object of the class BarcodeScanningProcessor. What you can do is change the constructor in the BarcodeScanningProcessor class to accept a context and then you pass in your LivePreviewActivity's context.



This is what the code should look like:



In BarcodeScanningProcessor:



  public BarcodeScanningProcessor(Context context) {
// Note that if you know which format of barcode your app is dealing with, detection will be
// faster to specify the supported barcode formats one by one, e.g.
// new FirebaseVisionBarcodeDetectorOptions.Builder()
// .setBarcodeFormats(FirebaseVisionBarcode.FORMAT_QR_CODE)
// .build();
detector = FirebaseVision.getInstance().getVisionBarcodeDetector();
this.mContext = context;
}


Then in LivePreviewActivity:



In the particular case of your activity you would do:



  case BARCODE_DETECTION:
Log.i(TAG, "Using Barcode Detector Processor");
cameraSource.setMachineLearningFrameProcessor(new BarcodeScanningProcessor(getApplicationContext()));
break;


Or if you just wanted to create an object of the class you could do:
BarcodeScanningProcessor bsp = new BarcodeScanningProcessor(getApplicationContext());



This should now give your BarcodeScanningProcessor class the context of your activity. Now, in BarcodeScanningProcessor, mContext should not be null and will have the context of your activity. I hope this answers your question.






share|improve this answer























  • So I am assuming that in your LivePreviewActivity you are creating an object of the class BarcodeScanningProcessor. What you can do is change the constructor in the BarcodeScanningProcessor class to accept a context and then you pass in your LivePreviewActivity's context. --- AHH! Let me give that a try. That makes sense.
    – Jamie Keefer
    Nov 20 at 17:05










  • Yes. Try the code above. I am certain that it should work now that your BarcodeScanningProcessor class will have the context of your activity. If it works, please mark this answer as accepted so that those with similar problems can refer to it and get help as well.
    – Ishaan
    Nov 20 at 17:08










  • Ishaan, I can not thank you enough for answering so quickly. I will certainly mark as accepted once I can verify it works, which I am confident it will. My android studio install needs to patch so it may be a while, I am about get on an airplane and this network is not patching very well :/. I will be sure follow up. Thank you very much.
    – Jamie Keefer
    Nov 20 at 17:22










  • You are welcome. I hope that when you land and test it, it works. Make sure that you are on a good network though!
    – Ishaan
    Nov 20 at 23:21










  • Hello Jamie. Have you been able to test my solution? If it didn't work, just post the problem you got below.
    – Ishaan
    Nov 21 at 17:20














1












1








1






So I am assuming that in your LivePreviewActivity you are creating an object of the class BarcodeScanningProcessor. What you can do is change the constructor in the BarcodeScanningProcessor class to accept a context and then you pass in your LivePreviewActivity's context.



This is what the code should look like:



In BarcodeScanningProcessor:



  public BarcodeScanningProcessor(Context context) {
// Note that if you know which format of barcode your app is dealing with, detection will be
// faster to specify the supported barcode formats one by one, e.g.
// new FirebaseVisionBarcodeDetectorOptions.Builder()
// .setBarcodeFormats(FirebaseVisionBarcode.FORMAT_QR_CODE)
// .build();
detector = FirebaseVision.getInstance().getVisionBarcodeDetector();
this.mContext = context;
}


Then in LivePreviewActivity:



In the particular case of your activity you would do:



  case BARCODE_DETECTION:
Log.i(TAG, "Using Barcode Detector Processor");
cameraSource.setMachineLearningFrameProcessor(new BarcodeScanningProcessor(getApplicationContext()));
break;


Or if you just wanted to create an object of the class you could do:
BarcodeScanningProcessor bsp = new BarcodeScanningProcessor(getApplicationContext());



This should now give your BarcodeScanningProcessor class the context of your activity. Now, in BarcodeScanningProcessor, mContext should not be null and will have the context of your activity. I hope this answers your question.






share|improve this answer














So I am assuming that in your LivePreviewActivity you are creating an object of the class BarcodeScanningProcessor. What you can do is change the constructor in the BarcodeScanningProcessor class to accept a context and then you pass in your LivePreviewActivity's context.



This is what the code should look like:



In BarcodeScanningProcessor:



  public BarcodeScanningProcessor(Context context) {
// Note that if you know which format of barcode your app is dealing with, detection will be
// faster to specify the supported barcode formats one by one, e.g.
// new FirebaseVisionBarcodeDetectorOptions.Builder()
// .setBarcodeFormats(FirebaseVisionBarcode.FORMAT_QR_CODE)
// .build();
detector = FirebaseVision.getInstance().getVisionBarcodeDetector();
this.mContext = context;
}


Then in LivePreviewActivity:



In the particular case of your activity you would do:



  case BARCODE_DETECTION:
Log.i(TAG, "Using Barcode Detector Processor");
cameraSource.setMachineLearningFrameProcessor(new BarcodeScanningProcessor(getApplicationContext()));
break;


Or if you just wanted to create an object of the class you could do:
BarcodeScanningProcessor bsp = new BarcodeScanningProcessor(getApplicationContext());



This should now give your BarcodeScanningProcessor class the context of your activity. Now, in BarcodeScanningProcessor, mContext should not be null and will have the context of your activity. I hope this answers your question.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 at 17:07

























answered Nov 20 at 17:02









Ishaan

8291417




8291417












  • So I am assuming that in your LivePreviewActivity you are creating an object of the class BarcodeScanningProcessor. What you can do is change the constructor in the BarcodeScanningProcessor class to accept a context and then you pass in your LivePreviewActivity's context. --- AHH! Let me give that a try. That makes sense.
    – Jamie Keefer
    Nov 20 at 17:05










  • Yes. Try the code above. I am certain that it should work now that your BarcodeScanningProcessor class will have the context of your activity. If it works, please mark this answer as accepted so that those with similar problems can refer to it and get help as well.
    – Ishaan
    Nov 20 at 17:08










  • Ishaan, I can not thank you enough for answering so quickly. I will certainly mark as accepted once I can verify it works, which I am confident it will. My android studio install needs to patch so it may be a while, I am about get on an airplane and this network is not patching very well :/. I will be sure follow up. Thank you very much.
    – Jamie Keefer
    Nov 20 at 17:22










  • You are welcome. I hope that when you land and test it, it works. Make sure that you are on a good network though!
    – Ishaan
    Nov 20 at 23:21










  • Hello Jamie. Have you been able to test my solution? If it didn't work, just post the problem you got below.
    – Ishaan
    Nov 21 at 17:20


















  • So I am assuming that in your LivePreviewActivity you are creating an object of the class BarcodeScanningProcessor. What you can do is change the constructor in the BarcodeScanningProcessor class to accept a context and then you pass in your LivePreviewActivity's context. --- AHH! Let me give that a try. That makes sense.
    – Jamie Keefer
    Nov 20 at 17:05










  • Yes. Try the code above. I am certain that it should work now that your BarcodeScanningProcessor class will have the context of your activity. If it works, please mark this answer as accepted so that those with similar problems can refer to it and get help as well.
    – Ishaan
    Nov 20 at 17:08










  • Ishaan, I can not thank you enough for answering so quickly. I will certainly mark as accepted once I can verify it works, which I am confident it will. My android studio install needs to patch so it may be a while, I am about get on an airplane and this network is not patching very well :/. I will be sure follow up. Thank you very much.
    – Jamie Keefer
    Nov 20 at 17:22










  • You are welcome. I hope that when you land and test it, it works. Make sure that you are on a good network though!
    – Ishaan
    Nov 20 at 23:21










  • Hello Jamie. Have you been able to test my solution? If it didn't work, just post the problem you got below.
    – Ishaan
    Nov 21 at 17:20
















So I am assuming that in your LivePreviewActivity you are creating an object of the class BarcodeScanningProcessor. What you can do is change the constructor in the BarcodeScanningProcessor class to accept a context and then you pass in your LivePreviewActivity's context. --- AHH! Let me give that a try. That makes sense.
– Jamie Keefer
Nov 20 at 17:05




So I am assuming that in your LivePreviewActivity you are creating an object of the class BarcodeScanningProcessor. What you can do is change the constructor in the BarcodeScanningProcessor class to accept a context and then you pass in your LivePreviewActivity's context. --- AHH! Let me give that a try. That makes sense.
– Jamie Keefer
Nov 20 at 17:05












Yes. Try the code above. I am certain that it should work now that your BarcodeScanningProcessor class will have the context of your activity. If it works, please mark this answer as accepted so that those with similar problems can refer to it and get help as well.
– Ishaan
Nov 20 at 17:08




Yes. Try the code above. I am certain that it should work now that your BarcodeScanningProcessor class will have the context of your activity. If it works, please mark this answer as accepted so that those with similar problems can refer to it and get help as well.
– Ishaan
Nov 20 at 17:08












Ishaan, I can not thank you enough for answering so quickly. I will certainly mark as accepted once I can verify it works, which I am confident it will. My android studio install needs to patch so it may be a while, I am about get on an airplane and this network is not patching very well :/. I will be sure follow up. Thank you very much.
– Jamie Keefer
Nov 20 at 17:22




Ishaan, I can not thank you enough for answering so quickly. I will certainly mark as accepted once I can verify it works, which I am confident it will. My android studio install needs to patch so it may be a while, I am about get on an airplane and this network is not patching very well :/. I will be sure follow up. Thank you very much.
– Jamie Keefer
Nov 20 at 17:22












You are welcome. I hope that when you land and test it, it works. Make sure that you are on a good network though!
– Ishaan
Nov 20 at 23:21




You are welcome. I hope that when you land and test it, it works. Make sure that you are on a good network though!
– Ishaan
Nov 20 at 23:21












Hello Jamie. Have you been able to test my solution? If it didn't work, just post the problem you got below.
– Ishaan
Nov 21 at 17:20




Hello Jamie. Have you been able to test my solution? If it didn't work, just post the problem you got below.
– Ishaan
Nov 21 at 17:20













1














try this create Application class



import android.app.Application;

public class MyApplication extends Application {
static MyApplication instance;

@Override
public void onCreate() {
super.onCreate();
instance=this;
}

public static MyApplication getInstance() {
return instance;
}
}


Register in manifest file



<application
..
android:name="com.yourpackage.MyApplication"
..>
.
.
.
</application>


start activity using this MyApplication.



Intent intent = new Intent(MyApplication.getInstance(), SendScannedBarcode.class);
String message = scannedBarcode;
intent.putExtra(EXTRA_MESSAGE, message);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MyApplication. getInstance().startActivity(intent);





share|improve this answer





















  • I will review this option as well. Thank you for the prompt reply.
    – Jamie Keefer
    Nov 20 at 17:23
















1














try this create Application class



import android.app.Application;

public class MyApplication extends Application {
static MyApplication instance;

@Override
public void onCreate() {
super.onCreate();
instance=this;
}

public static MyApplication getInstance() {
return instance;
}
}


Register in manifest file



<application
..
android:name="com.yourpackage.MyApplication"
..>
.
.
.
</application>


start activity using this MyApplication.



Intent intent = new Intent(MyApplication.getInstance(), SendScannedBarcode.class);
String message = scannedBarcode;
intent.putExtra(EXTRA_MESSAGE, message);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MyApplication. getInstance().startActivity(intent);





share|improve this answer





















  • I will review this option as well. Thank you for the prompt reply.
    – Jamie Keefer
    Nov 20 at 17:23














1












1








1






try this create Application class



import android.app.Application;

public class MyApplication extends Application {
static MyApplication instance;

@Override
public void onCreate() {
super.onCreate();
instance=this;
}

public static MyApplication getInstance() {
return instance;
}
}


Register in manifest file



<application
..
android:name="com.yourpackage.MyApplication"
..>
.
.
.
</application>


start activity using this MyApplication.



Intent intent = new Intent(MyApplication.getInstance(), SendScannedBarcode.class);
String message = scannedBarcode;
intent.putExtra(EXTRA_MESSAGE, message);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MyApplication. getInstance().startActivity(intent);





share|improve this answer












try this create Application class



import android.app.Application;

public class MyApplication extends Application {
static MyApplication instance;

@Override
public void onCreate() {
super.onCreate();
instance=this;
}

public static MyApplication getInstance() {
return instance;
}
}


Register in manifest file



<application
..
android:name="com.yourpackage.MyApplication"
..>
.
.
.
</application>


start activity using this MyApplication.



Intent intent = new Intent(MyApplication.getInstance(), SendScannedBarcode.class);
String message = scannedBarcode;
intent.putExtra(EXTRA_MESSAGE, message);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MyApplication. getInstance().startActivity(intent);






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 17:07









Mr X

785720




785720












  • I will review this option as well. Thank you for the prompt reply.
    – Jamie Keefer
    Nov 20 at 17:23


















  • I will review this option as well. Thank you for the prompt reply.
    – Jamie Keefer
    Nov 20 at 17:23
















I will review this option as well. Thank you for the prompt reply.
– Jamie Keefer
Nov 20 at 17:23




I will review this option as well. Thank you for the prompt reply.
– Jamie Keefer
Nov 20 at 17:23











1














Another way of handling the issue is create new constructor of BarcodeScanningProcessor which takes interface call back and once processing is done pass back result to caller.



   public interface BarcodeUpdateListener {
@UiThread
void onBarcodeDetected(Barcode barcode);
}


private BarcodeUpdateListener callback;

public BarcodeScanningProcessor(BarcodeUpdateListener callback){
this.callback = callback;
detector = FirebaseVision.getInstance().getVisionBarcodeDetector();
}


Once you get the result pass result to caller



callback.onBarcodeDetected(<Barcode>)





share|improve this answer





















  • I will review this option as well. Thank you for the prompt reply.
    – Jamie Keefer
    Nov 20 at 17:23
















1














Another way of handling the issue is create new constructor of BarcodeScanningProcessor which takes interface call back and once processing is done pass back result to caller.



   public interface BarcodeUpdateListener {
@UiThread
void onBarcodeDetected(Barcode barcode);
}


private BarcodeUpdateListener callback;

public BarcodeScanningProcessor(BarcodeUpdateListener callback){
this.callback = callback;
detector = FirebaseVision.getInstance().getVisionBarcodeDetector();
}


Once you get the result pass result to caller



callback.onBarcodeDetected(<Barcode>)





share|improve this answer





















  • I will review this option as well. Thank you for the prompt reply.
    – Jamie Keefer
    Nov 20 at 17:23














1












1








1






Another way of handling the issue is create new constructor of BarcodeScanningProcessor which takes interface call back and once processing is done pass back result to caller.



   public interface BarcodeUpdateListener {
@UiThread
void onBarcodeDetected(Barcode barcode);
}


private BarcodeUpdateListener callback;

public BarcodeScanningProcessor(BarcodeUpdateListener callback){
this.callback = callback;
detector = FirebaseVision.getInstance().getVisionBarcodeDetector();
}


Once you get the result pass result to caller



callback.onBarcodeDetected(<Barcode>)





share|improve this answer












Another way of handling the issue is create new constructor of BarcodeScanningProcessor which takes interface call back and once processing is done pass back result to caller.



   public interface BarcodeUpdateListener {
@UiThread
void onBarcodeDetected(Barcode barcode);
}


private BarcodeUpdateListener callback;

public BarcodeScanningProcessor(BarcodeUpdateListener callback){
this.callback = callback;
detector = FirebaseVision.getInstance().getVisionBarcodeDetector();
}


Once you get the result pass result to caller



callback.onBarcodeDetected(<Barcode>)






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 17:18









Ramesh Yankati

63848




63848












  • I will review this option as well. Thank you for the prompt reply.
    – Jamie Keefer
    Nov 20 at 17:23


















  • I will review this option as well. Thank you for the prompt reply.
    – Jamie Keefer
    Nov 20 at 17:23
















I will review this option as well. Thank you for the prompt reply.
– Jamie Keefer
Nov 20 at 17:23




I will review this option as well. Thank you for the prompt reply.
– Jamie Keefer
Nov 20 at 17:23


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397880%2fhow-can-i-find-context-and-start-a-new-activity-from-android-firebase-ml-kit-bar%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen