I have an application that works with the database.
When I exit the application when I click the "exit" button, it sends the data to the server.
There is a bug: when I remove an app from the recent apps, data is not sent to the server.
How can I fix this?
I want the data to be sent to the server when the application is removed from the recent apps.
You could spawn a Service during onDestroy, which lets you know when the activity is finished, and send the data from there.
https://developer.android.com/guide/components/activities/activity-lifecycle.html
Related
I want to write an app that whenever user 1 touches the "buzz button" in the app,
immediately user 2's phone vibrates.
I have written the app code and when user 1 clicks on the button, a request sends to the server via post method and the database updates.
so I can send the vibrate request to the sever.
but what should I do to force the app always listen to the server that when a request sent to it, phone vibrates.
And if you recommend any other ways please share with me!
I also need to store the buzz history in a SQL
To manually handle background process use Service:
https://developer.android.com/guide/components/services
And when event occurs use Broadcast:(to send events to other Fragment/Activity/Application)
https://developer.android.com/guide/components/broadcasts
to hear the broadcast events Register it to Receiver:
https://developer.android.com/reference/android/content/BroadcastReceiver
JobScheduler can also be used in modern android applications:
https://developer.android.com/reference/android/app/job/JobScheduler
i have made an app where i made a unbound service that is continuously requesting to server api, if server send json then notification will show and on notification click i take the user to one activity to show some data. everything working well while apps is opened or background. but when the app is closed, notification showing but when on notification click trigger to specific activity, there is no data showing(data should come through a server req).
what is the best way to do this?
The app
So I'm developing a chat app using GCM. The app works as follow: In a list of users, I can choose with which one I want to talk. Then a request is sent to this user and he has to accept it in order to start the chat. It's like the first user opens a chat room and wait for the other o join in. Im doing all this communication using special flags through GCM messages. Note that a user only exchanges messages inside a "chat room". There's no notification for him if he is outside a chat room.
The problem
When a user leaves the chat room I make him send (through onDestroy()) a message through GCM to tell the other user that he is disconecting and therefore the other user won't be able to send him messages anymore. But what if this first user leaves the chat room without calling onDestroy()? (Like closing the app, the app crashes, internet goes down, etc...)
Solution so far
When the user sends or receives a message I update his last_seen attribute on my database so I can know more or less if he is still online. So I have a cron job on my server checking from x to x seconds if the users of an active conversation are online and closing it if one of them are not. Note that the proccess of updating the user last_seen attribute is really heavy since I have to make an HttpRequest everytime I receive a GCM message (when sending I already have to make an HTTPRequest, so its not a big problem) and that's why I don't like this solution...
Question
Any ideas on how to know if the user is not there anymore?
Thanks in advance, any ideas are welcome
You could perfectly use the onStop() method of your chat room activity:
Called when the activity is no longer visible to the user, because another activity has been resumed and is covering this one. This may happen either because a new activity is being started, an existing one is being brought in front of this one, or this one is being destroyed.
Followed by either onRestart() if this activity is coming back to interact with the user, or onDestroy() if this activity is going away.
Set the status as online as long as that event doesn't trigger, if it does, send the last_seen parameter and assume he is no longer in the chat room.
I was wondering, when do you requery your server after receiveing GCM message, that is not "notification-worthy"? Should I even use it for this?
Lets take Facebook-like application and the event of somebody posting a status update.
My naive implementation of this would be as follows.
The server method that inserts the status into database, and then generates a gcm message to everyone who is friends with the person who made the post.
Now, in the GCMIntentService.onMessage() you receive the tickle. What do you do now?
1) Requery the server for new data right there? This means it would download stuff even tho the app is not running. (battery?)
2) Save some flag (indicating there is new data to be synced) in the preferences and next time the app is started,read that flag in onCreate() and requery server if neccessary?
3) Save the flag, do a broadcast to the activity. The activity, if running, receives the broadcast and shows some toast (crouton) that theres new data and allows user to click refresh (like Facebook does). If its not running, just save the flag and load new stuff on apps next start, if flag is raised.
4) I shouldnt use GCM for not notification-worthy stuff
Ideas?
(The following question is for mobile platforms in general (iPhone, Android, Blackberry))
We are integrating chat functionality into our existing application. I designed the system with a .Net web service and Sql Database to keep track of chat messages. Everything's working fine so far, when the chat window is open.
I need a way to notify the user of a new message when he/she is not currently viewing the chat screen (meaning either the app is not in the foreground or they are in another section of the app (not the chat screen).
Obviously, push notifications would be perfect here, but I'm not sure when I should be sending pushes.
How would the client sending the message know whether or not the other guy is viewing the chat screen? Should I just be sending pushed with every single message and have the receiving device decide whether or not it needs to pop up a window or display something in a nofication bar?
It seems like overkill to be pushing every single time a message is sent. How is this normally done?
Any ideas at all would be greatly appreciated.
Thanks.
First and foremost, keep in mind that your server will act as the broker for all messages passed between different chat clients. Here's how this could work:
User A initiates a message for user B
Message gets sent to the server.
Server determines that this message is for user B.
Server initiates a push notification and delivers the message to user B.
Now why would you need to push every single chat message? Because the only other way for your users to get notified would be to poll your server for new messages. Constant polling (at whatever rate you determine) is extremely bad in the mobile realm due to limited resources (battery, networking, etc.)
In a push notification scenario, it is up to your application to handle the logic of whether the user is notified on receiving a new message. What this means is that when user B receives a new message from user A, it's up to you to decide if you wish to notify B (i.e. bring your app to the foreground) or not. In either scenario, you want to use push notifications instead of polling.
On a similar note, user B does not necessarily have to know that user A's application (your app) is in the background which is why you will need to handle that logic (within your app) appropriately.
Push notification normally is applied to the application if it is not in the foreground. It is a way to wake-up the application to handle a new transaction from the server. Basically, a push notification is to be done if the client is running in the background and a new message is ready to be fetched from the server. As long as the new message is not fetched, if other messages arrive on the server, a push notification should be sent to the application.
Push notification is not necessary if the application is still running even if the user is viewing other screens of the application. It is however important that a thread is handling the connection to the server which is "patiently" waiting for transactions from the server.
One question, what protocol are you using for the messaging?.. Is it OMA IMPS protocol?