Camera Permission getting asked twice - java

So I have an app where I get access on the camera. I am doing all the permission things like described here. In the end when the user denies the access, which happens in the onRequestPermissionResult function, I call onBackPressed(I also tried finish).
Now as expected after I deny the access, I don't get into the camera and go back to my service. Now the permission box appears the second time and I don't understand why, since onCreate isn't called anymore after I finish, right?
How do I get the second permission box away after I already denied access through the first one that popped.
Thanks for any help!

Try saving the result into shared preferences if they accepted or rejected then you can check if it has been rejected before you call for the request.
Link on shared preferences:
https://developer.android.com/training/data-storage/shared-preferences

Related

So am building an app and it has this feature that i dont know exactly how to go about it

I hope this makes a bit sense, basically, I have this feature in my app for tracking calories which consists of having this page that only appears the first time you use the feature and it asks you to add personal details (so it can make the right calculations), after that you get faced with a simple page that tracks your nutrition with a button for the user to insert the meals he has eaten, this page has to save the inserted data (via firebase) and then restart from 0 each and every day.
my first problem is I don't know how I make the page that only appears one time to save personal data(to be more precise I don't know how to make only appears the first time). and the second problem is how do I make the app automatically sends the given data at the end of each day?
interface in normal state, interface when adding the meals
hopefully, this 2 images will help you get a better grasp of what am trying to explain
don't worry am not looking for someone to straight up solve it all for me, I just need some orientation about what type of things/functions I need to do to solve these 2 problems
While #Narendra_Nath's answer might work, please note that is not a bulletproof solution. Why? Because a SharedPreferences doesn't persist across app uninstalls. This means that your user can install and uninstall the app and see the page as much as they want. So if you indeed want a user to see a screen only once, then you should consider storing that data in a database. Please note that SQLite isn't also a solution because when a user uninstalls the app, everything that is stored locally is wiped out. So what's the solution?
The best way to solve this would be to store the data in the cloud, either in Cloud Firestore or in the Realtime Database. So you can set a boolean variable and always check against it.
If you however intend to implement Firebase Authentication, then another solution would be to display the screen when your users are authenticated for the first time. So even if they will try to sign in on another device, install and uninstall the app, they won't be able to see the screen again.
Regarding the second problem, you should consider using Cloud Function for Firebase. It's the most elegant solution. If you want to somehow schedule an operation, then you should consider using Cloud Scheduler, as explained in my answer in the following post:
Is it not possible to have a code in the background who will be called every 24h?
Make the page that only appears one-time -> store a value in the shared preferences "isInfoShownToUser -> false" then do a check when the app starts to check if this value is false or true. If it is false show the "take the info" page .. then turn the value to false in the shared preferences.
How do I make the app automatically send data -> Use a Workmanager implementation to send data to the server (Firebase) at a particular time ..
Or use a implementation like the first one which uploads the data to the server just once everyday

How to continuously check for field/document change in Firestore - Android

I am trying to listen to my document using the Snapshot Listener method in Android.
I have a document called 'Mobile' and a field called 'UUID'. In 'UUID', I keep all the UUID's of the phones the person has logged into.
The problem with this code is that I am not able to get listeners continuously with this code. Can we use Android Services or something to continuously check for changes in the document or a field in the document.
I need to create a code which will be continuously checking the UUID field for any changes and the code should create a Toast accordingly.
I am also worried that this will kind of increase the number of read/writes for our database.
Can someone please help me? Thanks in Advance
The problem with this code is that I am not able to get listeners continuously with this code.
Why would you say that? This is what it does, it gets the data in real-time.
Can we use Android Services or something to continuously check for changes in the document or a field in the document.
If you want to get updates even if the user closes the app, indeed you need a service. For more info, please check my answer from the following post:
How to create firebase background service in Android?
I am also worried that this will kind of increase the number of reads/writes for our database.
Yes, it will increase for sure the number of reads/writes if you continue to keep the listener active. So for not paying extra reads/writes, you should remove the listener according to the life-cycle of your activity as explained in my answer from the following post:
How to set addSnapshotListener and remove in populateViewHolder in RecyclerView Item?

Stop form data being remembered

I have an android app, and i open webViews within it. now if someone types something into a textbox within my webView, the next time it is opened, it shows the suggestions (what the previous user typed).
How can i stop my webViews from storing the previous users entries?
The only way i can get rid of them is to delete all the data from my app, but i store other things in here, so dont want to delete all the data for my app.
Thanks in advance
try this
webview.getSettings().setSaveFormData(false);
here is full explanation
http://roysutton.com/2012/02/21/preventing-auto-fill-in-android-webview/

Storing State in Android

I have this listview that gets populated with the data that is downloaded from the internet.
Hence in the onCreate() method, I will run the async task to download the information and put it into the listview.
I placed a boolean value to whether if the list is downloaded or not during the saveInstanceState() method, this will work if the user gets out of the app from the home button and returns. However, when the user exits the program through the back button, the saveInstanceState() method is not run.
I do not want to download the list again, how can I check whether if it's downloaded before?
Check this out: Implementing the lifecycle callbacks
http://developer.android.com/guide/topics/fundamentals/activities.html
Use the callbacks to get noticed what happens to your activity and react if nesseceray.
You can use the Shared Preferences to store key-value data:
http://developer.android.com/guide/topics/data/data-storage.html
If you want to persist data beyond the LifeCycle of the application, you'll need to store it outside the Bundle.
Your options are:
Shared Preferences
Internal Storage (on Device)
External Storage (memory card)
Local Database
Network (which would probably defeat your question)
I'd suggest a private Internal Storage file for saving your data.
You can override Activity.onBackPressed() and save your state there as well.
Also, you can do
void onPause() {
if(isFinishing()) {
// save your state. maybe you'd be better off with using preferences (or other things suggested by people here), so you don't need to worry about the instance state.
}
}

How to implement an Android detail notification?

This has probably been asked before, but I can't find a good way of implementing it. I'm trying to write a program that manages a form of messages, and these messages are received from an external data source. This all works. However, the problem comes when I try to notify the user: I would like to have the notification jump directly to the message when it is touched, but this seems to mess up the back stack. This is probably best explained by example:
I open up the message list, the main activity, and browse for a while.
I hit home and go into another app (let's say Music).
A new message is received. A notification comes up, which I touch. The message detail view is displayed.
Now I hit Back. What I want to have happen is that I return to Music, but unfortunately, Back sends me to the message list, and then hitting Back will return me to music.
The both the list and the detail activities are marked as "singleTop", and the exact flags that I use for the notification Intent are:
FLAG_ACTIVITY_NEW_TASK
FLAG_ACTIVITY_CLEAR_TOP
FLAG_ACTIVITY_SINGLE_TOP
I figure if the Messaging application can do this, why can't I?
I have found one way to do this, but it's still not ideal:
Change the detail activity to have a different task affinity from everything else.
Add android:launchMode="singleTop" and android:excludeFromRecents="true" to the detail activity's manifest entry.
(Optional) Modify the list activity to open the detail activity with FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET. (This makes the task more like the built-in messaging app.)
The only fault to this scheme is that switching back over to the app will always go back to the list activity, but at least it is consistent. If someone else has a better way to do this, I'd love to hear it.

Categories

Resources