I have been struggling with this issue for weeks now and I don't want to give up! Here is my problem:
Problem Definition
I have successfully logged in a Facebook user using Facebook SDK. This happens immediately after they choose a photo to share on their wall.
The first attempt to post the image works effortlessly and the user gets redirected to a different view once they are done posting to their wall.
Here is where things don't work:
When the user tries to login again to post another photo for instance, they are allowed to login but then the screen goes blank and nothing gets posted to their Facebook wall.
I don't know why it is acting like this and I cannot figure out where it dies exactly.
Things I have tried so far
I have, since I am making three async calls, created a timer (Thread) which checks to see if the calls have been completed, then calls:
Session.getActiveSession().closeAndClearTokenInformation();
This, does not solve the problem.
I have also tried using a counter variable that gets incremented each time an async task is completed and then I check to see if the number is 3 before clearing everything up. This still fails.
I am stuck and I really need your help. Sorry for the long question - I just thought I should give enough details.
Thanks,
E
I ended up solving this problem on my own and here is what I did:
Define a local variable called isPosted which is a boolean and set its initial state to false.
In the first async task, either do nothing with it inside onCompleted() method or set it to false again just in case something set it to true;
Repeat this until you reach the last async task - the one to be executed last.
In the last request/async, set it to true.
After calling the methods that execute those async tasks, check to see if the variable is true - in that case, clear the session and token information. If needed, clear the cookies as well. This will logout the user completely and create room room for others.
This enabled multiple users to login one after another and a single user can login consecutively without issues and post to their wall.
Related
I have added to my phone authentication to my sign up process, in a send code activity - which sends the sms code to confirm the phone authentication process. Then, I have also added a "go-back"/"return" button which moves the user back to the main activity.
If I make the following request which sends the user a sms code to his phone:
PhoneAuthProvider.verifyPhoneNumber(options);
I won't be able to make another request before the defined timeout duration ends. Therefore, I thought about the easy and not messy approach, that would be to cancel the ongoing request, but unfortunately couldn't find how to do so, if even possible nowadays. I have also saw the unanswered post here: Android Firebase OTP auth: Is there a way to cancel OTP code request programatically before the actual timeout?
Couldn't work with this, even though it's what I am looking for, but it has no related answers.
Note: I am programming my project with Java and not Kotlin.
I have also thought about the second approach, which is to save current activity's phone number and then extract it with onRestoreInstanceState and onSaveInstanceState, then resend a code sms again. But of course, it's much more complicated and messier.
It is possible to cancel an ongoing verification request by calling the verifyPhoneNumber method again with the same phone number, but with the forceResendingToken parameter set to null. This will cancel the previous request and allow to start a new one.
It is also possible to use the PhoneAuthProvider.getInstance() method to get a reference to the PhoneAuthProvider instance, and then call the verifyPhoneNumber method on that instance instead of calling it directly. This allows to call the verifyPhoneNumber method multiple times without canceling the previous request.
Timeout duration for verification requests is typically around 5 minutes, so if you want to allow the user to request a new code before the timeout expires, provide a way for them to do so, such as by adding a "Resend code" button to the app.
Overall, it's best to design apps in a way that minimizes the need for canceling ongoing verification requests, as this can lead to a confusing user experience. Instead, focus on providing clear instructions and options for the user, and consider using the getInstance method to avoid having to cancel requests altogether.
Synopsis: I need a way to start a task and have it persist through onDestroy() of app until it completes, or ability to pick up where it left off.
In my app, I have a ListView containing some items from a database. Hopefully only about 10-30 items, but potentially thousands (if the user never clears it, although I have prompts to clear it from time to time).
I have set up an AsyncTask to perform clearing the selected items from the list when the user wants to. However, I've noticed that the AsyncTask is killed when onDestroy() is called, for example if the user selects all items to delete, presses delete, then swipes app out of Recents while task is still performing.
I remember learning somewhere that a Service persists longer than an AsyncTask, so when the task gets killed I hand off the data to delete to a Service that I created. It does this by
intent.putIntegerArrayListExtra(list);
and get data from it in the Service. The Service persists far longer than the AsyncTask (only about 4-6 seconds), but still not all the way to completion. I know a little about START_XXXX flags, but that would be bad practice for this task, since they'd either send the whole list back to itself, or never really stop.
What is the preferred method to delete selected items from a database without it stopping when the app is killed, or at least to pick up where it leaves off?
Thanks all!
Your problem is very much like this: You have an application open in your favorite OS which is doing things in the background and then in the middle of it, the user force closes it. Logically, it will stop everything it's doing and stop executing and there's not much you can do to interrupt it.
There's no ideal solution to stop this from happening so what most people end up doing is to warn users that stopping the app when this operation is in process can have unwanted consequences.
In Android however, you have another option which is slightly more robust: you can write a persistent background service what continues running even if your app isn't running, but that still wouldn't solve the problem of what happens if the user switches off the phone when you're deleting from the DB? which would be the next logical question given your context. (personally, I would not recommend this approach for your task).
Best you can do is to maybe write a shared preference for every row you've not yet deleted (this will be the full list of rows you want to delete when you start deleting). For every row (or bunch of rows) you delete, change this preference to remove those rows from the preference and then if the app is interrupted, when you restart your app, read this preference and continue where you left off.
Alternatively, do what others do and warn users (by use of dialogs for instance) that they shouldn't stop the app until the delete is done otherwise bad things happen, etc.
I would strongly discourage you from using a service simply because it lasts longer than an AsyncTask. That's way too hacky and not at all reliable.
I have a startingActivity on Google-glass
I want to run it sometimes silently,
meaning it will run, communicate with the server,
get and send data - but the user won't see the app.
The user will see a static card from time to time,
but basically can be in a context of another app.
my tries:
I have thought to create a service instead of my
startingActivity,but there are too many things that relays on the main UI views
If I comment out the setContentView(), all my code that refers
view.findViewById() will fail. no? and besides the user will see a
black screen instead of silent run which i desire.
any other solution for silent run, but yet running the
startingActivity fully?
I am using Crouton as alternative to native android toasts. I have to display 5-6 croutons one after the another and then call System.exit(0) to exit my app.
The problem is, I see first crouton for 1-2 seconds and the app just exits! The rest croutons aren't displayed at all. This is because when the code is being executed the undisplayed croutons are added to queue. And when it comes to System.exit(0) it exits the app without displaying those queued croutons. I have tried searching for solution for this and came across a solution in which I have to create a new thread, then sleep it for time = sum of durations of necessary croutons and then call System.exit in that thread. But then if I have more or less croutons in another situation then that becomes useless.
So can anyone think of a solution?
Why do you have to quit the app?
In general, in Android, applications should not quit, and show not provide a way for the user to quit them. Quitting an app is handled by the system when the user navigates away from it and goes back to the home screen.
If your application must quit (for example, because of an unexpected condition it can't deal with) and you want to make sure the user sees the information, then the best approach would be to use an AlertDialog to display the information.
So, long story short: revise your UI... if you're sure that this is the right way to do it, then simply don't call System.exit(0). Just show the toasts and then stick around. Eventually the system will decide to quit your app when memory is needed.
This question is continuation to my previous question over stack overflow how-to-download-images-asynchronously-from-web-server . I am struggling to make the asynchronous list in blackberry. Now it is working fine for me. But it is giving me another problem now.
What I have done so far
Created a list view taking value from the XML feed
List is loaded with default thumbnail
Created RunnableFactory, limiting the thread pool size to 5 and then adding the runnable's to it. Runnable objects has the capability to download the image from server.
Now list loads perfectly fine asynchronously.
Problem scenario
On loading of the list screen it is initializing the RunnableFactory and then starting download and render images in list. But, let say I have 50 number of rows in the list. And now 10 images downloaded successfully, and RunnableFactory is still in action. At this point press back key and then click next. Practically it should come to the list screen and then again initiate the download process freshly. But it is throwing IllegalThredState exception
My assumptions on this problem
As all the threads are running, I might have to cancel all of the threads on back key pressed. If this is the problem can you please let me know how could i do it? As i have created multiple threads how could i manage to stop all threads and then navigate back ?
This looks like a more complex system. can anyone help me to understand what else could be the possible fix for this problem?
I got this exception when I tried to start thread second time after finished run. Once started, a Thread may not be restarted.
if you are using any treadpool then you shutdown otherwise you can inturupt all treads on navigate to back.