I am using an android QR code processing library - android QR code.
I am extending the DecoderActivity for scanner and now I want the scanner to be inside a fragment, I have used LocalActivityManager
to embed Activity inside a fragment. Here is the code:
public class QrCodeProcessorFragment extends SherlockFragment {
private static final String KEY_STATE_BUNDLE = "localActivityManagerState";
private LocalActivityManager mLocalActivityManager;
Button generate_qr_code;
private QuickPayManagerActivity parent;
protected LocalActivityManager getLocalActivityManager() {
return mLocalActivityManager;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle state = null;
if (savedInstanceState != null) {
state = savedInstanceState.getBundle(KEY_STATE_BUNDLE);
}
mLocalActivityManager = new LocalActivityManager(getActivity(), true);
mLocalActivityManager.dispatchCreate(state);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// This is where you specify you activity class
Intent i = new Intent(getSherlockActivity(), CaptureActivity.class);
Window w = mLocalActivityManager.startActivity("tag", i);
View currentView = w.getDecorView();
ViewGroup vg = (ViewGroup) (currentView.getParent());
if (vg != null)
vg.removeView(currentView);
currentView.setVisibility(View.VISIBLE);
currentView.setFocusableInTouchMode(true);
((ViewGroup) currentView)
.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
return currentView;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBundle(KEY_STATE_BUNDLE,
mLocalActivityManager.saveInstanceState());
}
@Override
public void onResume() {
System.out.println("lam onresume");
super.onResume();
mLocalActivityManager.dispatchResume();
}
@Override
public void onPause() {
System.out.println("lam onpause");
super.onPause();
mLocalActivityManager.dispatchPause(getActivity().isFinishing());
}
@Override
public void onStop() {
super.onStop();
mLocalActivityManager.dispatchStop();
}
@Override
public void onDestroy() {
super.onDestroy();
mLocalActivityManager.dispatchDestroy(getActivity().isFinishing());
}}
QR scanner is not working now. I debugged the library code, it is expecting an activity instance and I am passing the activity instance which is inside the fragment. Hope I am clear on this. Please help!