OnActivityResult not executed - android

enter image description here
When I call the system camera through the above codeļ¼Œthe onActivityResult method does not perform on some phones,For example, Samsung S4,That's why.Ask for help

There are 2 possible solutions:
You should try with request code larger than 0.
Does your activity contain singleInstance or singleTask launchMode? check this issue .

next time please add the source code. its easier that way.
and the logcat if some error is there.
but it seems that what you want to achieve is something like
Android ACTION_IMAGE_CAPTURE Intent

Related

Is it possible to check a second Espresso Intent matcher after you receive the result from the first one?

When using the intended(IntentMatcher) from the Android Espresso API, is it possible to do this twice in the same Activity?
So for example I click a button which starts an Activity for result. I check that this Activity has fired using intended(IntentMatcher). That works.
However, when I get the result, I want to fire off an Intent for a different Activity. In this case just a local Activity in the same app package with no result.
When I do this manually in the app it works fine, but Espresso can't seem to detect the second Intent in my test. What I am I missing or is this not possible? Alternatively, how should I be doing it? Maybe my design is bad.
When I do the check I'm trying this:
intended(toPackage(<packageName>));
intended(hasComponent(hasClassName(<className>)));
The first line matches but not the second one. And even if the second line is not completely correct it never seems to show anything in the error log about the second Activity I'm actually starting.
Another thing adding to the confusion is that two intents are definitely being fired as it shows that in the log. They both seem to be the same one but with slightly different details - one is a package, one is a component. Does it log the result from the first Intent as an Intent in itself? Sounds unlikely but where is this other intent coming from? I know it's not the second Activity I'm launching as it still fires even when that Activity isn't called (when the first Intent result is a fail).
I've also considered that maybe it's not getting detected because it's not waiting long enough for the second intent to fire. If that were the case, what would I do about that? I don't see much talk about handling time sensitive things in Espresso. Like checking if a progress bar is shown but then hidden again while not pressing anything. How do you do that? Maybe it's the same answer.
Any help appreciated!
Ok I found the problem. My IdlingResource wasn't working.
After fixing that it works like a charm :)

onCreate() method is triggered when I use my device gallery

I'm trying to create an application where there is a need of uploading images from my mobile. In this case, when I open my Gallery and choose a image and come back to my application, onCreate() is called again due to which the TextView, EditText and the booleans which I've used earlier are cleared.
Can you please help me how I can solve this issue.
Your activity is getting destroyed due to memory issue you might be doing some bitmap op or something check it out also try adding large heap=true in manifest

How can I know if the user took screenshot of my app?

My app represents funny sentences that my users upload, and in order to know which sentences are better I want to know if the user has taken a screenshot. The only related thing I found is from Google Maps. Anyone know how to make a "screenshot listener" or which method it invokes? Thanks.
One way to do this is by creating a class which is implementing FileObserver. Then add listener when you are loading activity ( by using onStart() activity's method) and remove listener when you are going out of your activity (by using onStop() activity's method).
Once you get FileObserver event, you have to be sure that is a picture creation.
Note that this method is not 100% safe but it's simple to make it works !

Android app force closing

I'm new to Android app development and Java in general. I have been watching some tutorials but decided it was time to start doing something on my own. I'm trying to make a fat caliper calculator where I insert all the info in one activity, calculate it and then pass the results on to another activity for displaying it. For some reason I'm getting a force close every time I hit the calculate button and I'm not sure what's causing it or which activity.
Here's the code:
MainActivity
Display
Can you see what's causing the force closes?
Thanks.
The problem is you are starting display Activity but not passing bundle to the Display Activity.
Change your code like this when you are starting Display Activity.
Intent a = new Intent(MainActivity.this, Display.class);
a.putExtras("giveResults",packet );
startActivity(a);
I believe its because where you are starting your activity, and your bundle, your not adding the bundle to the intent.
You would need to do something like
a.putExtra(packet)
before you start the activity
Take a look at this answer. It describes LogCat which is the best way to debug android code.
https://stackoverflow.com/a/3280126/771999
If you use LogCat you can usually pinpoint the exact line number of your issue.

Saving State With Android

I have an app that will never require more than one instance of an activity. I want it so that when the user comes back to a screen it is in the same state as they left it except for a few places where it doesn't make sense. I've worked out saving the persisted data with onpause onstop updates. However to keep the screen looking the way it did when they left it i use intents specifically setting the flags to Intent.FLAG_ACTIVITY_REORDER_TO_FRONT|Intent.FLAG_ACTIVITY_SINGLE_TOP then startActivity. It seems to work great but does it make sense? Is there a smarter way? Pitfalls doing it this way etc... any feedback will be greatly appreciated.
android:launchMode = "singleTask"
add the above line for every activity in the manifeast file. Adding these launch relaunch the activity instead of creating the activity again.
Refer this link

Categories

Resources