I have created Collection Widget and in which I need to updated data through API. Everything seems to work fine but ListView update call is executed only once. While debugging I found that onGetViewFactory() method is getting called only once.
I have searched for the problem and used the solution from below link
onGetViewFactory only called once for multiple widgets
But it didn't work for me.
Related
I am restructuring my code to use ActivityResultContracts, and I've been able to recreate the old way of doing things with onActivityResult by passing in "codes" with my Intents and just passing them back from the called activity. Everything is working fine, but how would I manage to do that with App Updates, even the Google documentation is still using onActivityResult to check for app updates.
After looking at it for the past few days, it does not seem like it is possible to forgo using onActivityResult; the cancel response is only returned to that method. If you have a listener setup to check for resumed downloads, you will get a response there (as onResume is called when the calling activity is moved back to the foreground) but you only get that an update is available and the install status is unknown (which coincidentally is the same value as cancelled, and you can't do anything there as you get the same values on the initial call to check for an update). I don't see the point in deprecating a method you're still required to use, but oh well.
I'm making an Android app with Firebase and within one of my activities I need to read data from Firebase before doing anything else. To do so, I'm using a ValueEventListener. The problem is, Android is running the rest of the code first and then it gets the result/runs the code within the listener's onDataChange() method. I know this because I debugged using Logs and indeed the result arrives a couple of seconds after the rest of the code runs.
I've seen examples of people writing the code you want to run after the query within another method, and then calling that method inside the onDataChange(). I tried doing that, also tried moving the listener to another class and calling the method and even tried controlling the flow of the code with variables, nothing worked. Any ideas of what can I do?
Btw, I don't know if this affects in any way of not but, my piece of code that depends on Firebase's result is inside the onStart() method, so I suppose Android would always run the onStart() first and then get the result from the listener.
Thanks!
The ValueEventListeners are asynchronous, so they won't run first. Instead, try calling a function that does what you wanted to do with the listener from inside the onDataChange() function.
I am developing a simple app which will speak the contact name or an unknown number when call is received. I am implementing the app using broadcastReceiver and Services. If i run the app on emulator and start the call using DDMS, with 2 or 3 contacts saved, the app works fine since onInit() is called before tts.speak() runs.
Now when i try to run the same app on my android phone, onInit is called after the tts.speak(). From what i have understood while searching for an answer to this question, this happens due to tts.speak() not waiting for onInit to called.
One solution i found on this question was on How to wait for TextToSpeech initialization on Android but that didn't work either.
This question has been asked a lot of times but i couldn't find a working solution. This link suggested to use handler http://davidcheney.wordpress.com/2010/11/16/multitasking-in-android/ but being a newbie i have no idea as to how to implement that.
From what i understood i have to wait till onInit is called before i can use tts.speak() but i don't know how to do it.
Update
I was trying to call speak function outside the onInit since the data which was to be spoken was coming from elsewhere and i didn't want to do all the coding in onInit,this was not working. So i changed my code and finally somehow managed to run that speak() inside onInit().
Although the code is now running but there must be a way to call speak() outside onInit. So i will wait for a better answer else post my code for others facing same problem.
You either set a class member flag boolean mTtsInitialized and check this flag everytime you call speak or put the code to get the data to be spoken in onInit
This is not the most elegant way of handling this, I'm sure, but could you extend the class containing the onInit() method?
In this class, you could have a boolean variable that effectively "locks" your thread. Override the onInit() method, call super(), and then after super() set this value to true. Then, enter a loop that blocks the thread which calls tts.speak() until this value is true.
You'll want to keep in mind that you can't do this in the UI thread, because if you block that for too long it will crash your app.
I hope I understood your question correctly. :)
I have an activity for updating a table which holds configuration data for a service. I am using a SimpleCursorLoader and the SupportLoaderManager to update the listview in that Activity. I destroy the loader in In the activity's onDestroy. This may not be relevant, since the issue I'm seeing happens even without visiting this Activity.
I have a service as well, that registers a ContentObserver on the URI to the table that is modified in the Activity above. It reads its configuration, sets itself up and registers a ContentObserver on that table in the Service's onCreate. In the Service's onDestroy, that listener is unregistered.
This is only 1 of a few databases/tables that I have in my system. What I'm seeing is that when I make an update to a completely different table, the ContentObserver on this configuration URI is being triggered. The Authorities are completely different, they interact with different SqlLite databases, they're even running in different processes within the application. I removed all "notifyChange" calls that I could find which would trigger the ContentObservers, yet they still are firing.
My question is, is there any way to find out who is calling the notifyChange that is causing the ContentObserver to fire? Does the system outside of my application have any reason to notify observers of a URI? I'm trying to track it down, but without having any clue where the notify is coming from, I'm running into a wall.
Again, only a few hours away from the answer. I apparently didn't find all of the notifyChange calls in my code. The offender was:
getContentResolver.notifyChange(new Uri.Builder().build(), null);
which was calling notify on a blank Uri. It doesn't appear to be noted in the documentation, but the behavior I saw was that this triggered all of the registered ContentObservers to be fired in my application. I got that line out of there, and now everything is notifying as it should.
The answer to my original question, "Is there a way to find out who called notifyChange on a Uri?," I think the answer is "Look harder for calls to notifyChange in your code. Other than that, you're on your own."
I have strictly separated the layers between different parts of my Android application.
At some point of execution I am updating my data from xml service on Internet. That updating takes up about 10 seconds and is done completely in the background - meaning the user interface of an application works fine. However further calls to my class (later - DataManager) which is responsible for data updating (after update has been started but not yet finished) makes my application crash. NullPointerException is thrown with objects which NEVER are null.
So I assume that only one Thread can use my DataManager at one time and calls to DataManager from other threads ends up in exceptions.
I tried various combinations of putting 'synchronized' keywords near sensitive methods but it seems that when update is executing - NOTHING can use ANYTHING from my DataManager.
BTW other classes which are related to DataManager during the execution also seem to hold null objects.
I guess I am just missing some kind of design pattern which is used to deal with concurrency problems and maybe anyone can suggest me something?
I had trouble dealing with using the Apache http client because of threading issues and I think your issue could be similar in that respect. What I ended up doing was setting up a callback scheme. This may or may not work for you, of course.
This may seem a bit Rube Goldberg-like to you, but it worked for me.
I would have my UI thread call my data manager object with a method that spawned a thread to go and acquire the data. The method's return value is an object that would EVENTUALLY have the data in it. I would have my activity extend an interface, something like "DataCallbackInterface", with a method that the thread would call after it acquired the data (i.e. the last line in run()). Since that call will inherently be within another thread, you'll need to use a Handler to run anything useful in your implementation of the DataCallbackInterface method. When that method is called, you will know for a fact that the data is there and not rely on any strange synchronization flags to get it right.