Note that there are some explanatory texts on larger screens.

plurals
  1. POzxing onActivityResult not called in Fragment only in Activity
    primarykey
    data
    text
    <p>I'm having some issue with zxing onActivityResult().</p> <p>As you can see in the code I did properly invoke new intent as described in <a href="https://code.google.com/p/zxing/wiki/ScanningViaIntent">https://code.google.com/p/zxing/wiki/ScanningViaIntent</a>. </p> <p>The question is how can I catch onActivityResult() in Fragment, since I need this data in my Fragmnet and not in Activity?</p> <pre><code>package com.example.testingcodereading; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.ResolveInfo; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; public class MainFragment extends Fragment { private Button mButtonXZing; @Override public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState){ View v = inflater.inflate(R.layout.fragment_main, parent, false); mButtonXZing = (Button) v.findViewById(R.id.button_xzing); mButtonXZing.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { IntentIntegrator integrator = new IntentIntegrator(getActivity()); integrator.initiateScan(); } }); return v; } @Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { System.out.println("never here"); IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent); if (scanResult != null) { // handle scan result } // else continue with any other code you need in the method } } </code></pre> <hr> <pre><code>public class MainActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FragmentManager fm = getSupportFragmentManager(); Fragment f = fm.findFragmentById(R.id.fragmentContainer); if(f == null){ f = new MainFragment(); fm.beginTransaction() .add(R.id.fragmentContainer, f) .commit(); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); System.out.println("the code is catch"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload