Android barcodescanner still image with multiple ZXingScannerView - android

in my app I have a fragment using the dm77/barcodescanner.
I'm working on a shop app, ex: you scan an item -> page of product -> continue shopping -> open another scanner sessione -> etc.
Now, as you can see, because the clinet wants to maintain the back stack, multiple istances of that fragment could be open (but not at the same time).
The first fragment with the scanner works well, the others has a still image, even if I call
scannerView.stopCamera();
scannerView = null;
leaving the first fragment.
NOTE: the other fragment works well if, instead of add we use replace. But that will create problems on the fragment's animations.

After furious debugging, I found how to make all working:
When the fragment is visible / in use, create and add programmatically to your layout the ZXingScannerView, starting the camera and preview;
When the fragment is not visible / used, remove the ZXingScannerView from your layout;
On some android version (like 5.01) be careful to not call startCamera more than one time, otherwise you'll not be able to open it anymore until you restart the app. The error here is caused by dead thread exception.
Hope to have been enough clear and helpful.

Related

Fragment.OnStop is not called while Activity.OnStop is called

I have ActivityA which contains FragmentF.
ActivityA contains also NavigationDrawer infrastructure.
When I start the app - all is fine.
There are called (among others):
ActivityA.OnStart
FragmentF.OnStart
ActivityA.OnResume
FragmentF.OnResume
.. and content is shown.
But when I press home (to minimize app & show home screen) - here comes the problem:
ActivityA.OnStop is called
FragmentF.OnStop is NOT called
Interesting facts:
- if I switch items in NavigationDrawer then FragmentF.OnStop is called and content of another fragment is loaded in ActivityA
- in all cases (minimize the app & switch content in NaviDrawer) FragmentF.OnPause is always called
As a workaround I put code (expected to work in OnStop) to OnPause but wondering:
- why FragmentF.OnStop is not called
- how to make it called
I'm using Xamarin (thus CamelCase namie convention :) - but I don't suspect this platform for bug, it seems like Android native behavior.
First of all, I do not know what kind of specific layout in your project or use other plugins. I test it in my demo(Activity contains Fragment).
github.com/851265601/FragmentDemo
When i click the home button, Onstop of Fragment was called like screenshot in this demo. This issue may related other reasons, do you use Util.log to generate it and capture the log in logcat. Note: Don't put time-consuming operations in OnPause

Activity recreate issue in Android Nougat Only?

I have developed small project, in which there are three fragments added in a single activity.
I am getting an issue in Nougat only i.e.
Start the application and go from fragment 1 -> fragment 2 and in fragment 2 there is a single button on this button click open external browser and when press back button, activity reload again and start from fragment 1.
In below versions from Nougat it is working perfectly, it back on fragment 2 but in Nougat (Samsung Galaxy s8+) it activity reloads and starts from fragment 1.
so please help me to resolve this issue.
thanks
First check your code in onResume where if you are reloading the ViewPager or setting the currentItem.
Other Reason can be Don't keep activities activated. Can you check in the Developer tools to see if Don't keep activities is on?
You can check it from Device settings Like this:
Settings -> Developer Options -> Don't keep activities

Back button closes app after navigation but not before

I've got an xamarin forms/prism app, and my hardware back button does nothing on the initial page.
If I navigate to another page, it closes the app as expected. If I navigate to the initial page again, it also closes the app - but not if the app just started.
Is there something I'm missing?
My class App mainly has an OnInitialized that navigates to the initial page:
protected override void OnInitialized()
{
NavigationService.NavigateAsync( "MyMasterDetail/MyNavigationPage/StartPage", animated: false );
}
On MyMasterDetail, there are buttons that navigate to MyNavigationPage/SettingsPage and other pages like that.
It doesn't matter if I use Android 5 in Emulator or Android 6 on a real device, the behaviour is the same.
When using a MasterDetail as your root, you are not actually navigating anywhere else. You are simply changing the Detail property of the MasterDetail to another Page. This is not a navigation action. So you are not really navigating. If you want to fake it, you need to add the INavigationPageOptions to your MyNavigationPage and set the ClearNavigationStackOnNavigation property to false. This will continuously push new pages onto the MasterDetailPage.Detail MyNavigationPage without clearing the stack (PopToRoot). Then this will allow your bac button to behave like you are wanting.

Android open activity from fragment showing two screen separately

I have created an app. which contains MainActivity->inside fragments class loading with some UI works..
After I have tried to pass some datas to new Library Activity (inside one fragment available with make some works and need to get back result.)
Problem: when i open new activity, its showing two separate apps like..
starting Activity Page and Library Activity.. But, after entered library activity, finish the work and get back result to MainActivity Successfully..
Note: Even, Library Activity showing as a seperate App. thats my problem.
Please help..Thanks for Advance

Is it possible to detect when a new Fragment appears in an app?

I'm working on some testing tools and need to be able to determine when the UI of my app under test changes. If an app just uses Activities, I can use the Instrumentation.ActivityMonitor to detect when a new Activity is displayed. Is there anything analogous for Fragments?
It looks like FragmentManager.addOnBackStackChangedListener will let me detect some Fragment changes (when the old Fragment is pushed onto the back stack?) but will probably not fire if the new Fragment is shown without adding anything to the back stack.
Any pointers for how to detect when a new Fragment is displayed?
Thanks!

Categories

Resources