4

I am developing application in which is based on Login-Logout mechanism along with REST API integration.

For making REST API request TOKEN is required. Application is saving this TOKEN and other user details to SharedPreferences.

When User logged in application saves all required data and at logout time all data is removed from SharedPreferences and TOKEN entry is deleted from application server

Application also register with GCM server for sending push notification to user. For that application sends Device Register Id to application server.

But if User clears application data or uninstall then application will open login screen and register again with application server and GCM server so old entry remains in application server and new entry is added to server.

So if server send push notification to application then two push notification receives in device.

Is there any way to detect programatically if application data is cleared or application is uninstalled?

Any help will be appreciated.

Rajesh Jadav
  • 12,801
  • 5
  • 53
  • 78
  • Save one unique ID per user **on your server**. – showp1984 Oct 13 '15 at 13:37
  • 1
    Device registered id generated from GCM will be same for application. it changes rarely – Rajesh Jadav Oct 13 '15 at 13:39
  • *Is there any way to detect programatically if application data is cleared or application is uninstalled?* nope – Tim Oct 13 '15 at 13:41
  • 1
    If the user installs the app again and uses another username, then you should consider him as a new user. Otherwise, if he uses the same login details as before, just check if that user already exists and only update the details in the server. – SuperFrog Oct 13 '15 at 13:43

4 Answers4

3

Finally i came up with following solution.

I have implemented GCM 3.0 with Instance ID API for sending push notification to application using Application and GCM server instead of old GoogleCloudMessaging.register(SENDER_ID);

So when Application server try to send push notification to device then server gets “error”:“NotRegistered” response for old device id so based on that server will remove useless entry.

In GCM 2.0 server gets “error”:“NotRegistered” response sometimes even if application is installed but in GCM 3.0 it works perfectly.

Rajesh Jadav
  • 12,801
  • 5
  • 53
  • 78
1

It is always better to save public data in app itself like the login ID,public ID etc and not the secure data. Let your server also have the same public ID. So If your application data is cleared or uninstalled, the Login ID,public ID in the app also gets erased. So the next time he installs the app or tries to login from beginning, if he uses the same Login ID he would be assigned with different public ID. During the time of authentication with server, the server will try to match with already present Login ID but it gets to know that the public ID is different and hence would ignore your old publicID entry and create a corresponding new public ID for your loginID. In this way you can prevent 2 server push notifications for the same login ID.

  • *if he uses the same Login ID* but what if he does not? – Tim Oct 13 '15 at 13:59
  • Then cool, its easy. You have a new entry in the server for your new Login Id and a new Public ID. And he gets push notifications only for that login ID. It is more like for example you have a shopping app and you have 2 accounts for that and you are using it in a single device. At a time you can use only 1 account. So you get push notifications for that particular account/Login ID. –  Oct 13 '15 at 14:04
  • What to do with the lingering data on the service? the data of the account that is now not in use anymore – Tim Oct 13 '15 at 14:05
  • The data on the service also gets reset When the app is uninstalled or cleared. –  Oct 13 '15 at 14:09
  • app allows different types of user to login say(customer, vender). user first login with customer .this entry added to server now user uninstall app and reinstall again and login with vender so when any general notification is sent to both types of user. device will recieve notification for both user – Rajesh Jadav Oct 14 '15 at 09:49
0

You could use broadcast receivers for the uninstall and data erased:

ACTION_UNINSTALL_PACKAGE

and

EXTRA_DATA_REMOVED

You could have the program remove the registration in server, or have the server "timeout" registrations that remain idle for too long.

Bonatti
  • 2,778
  • 5
  • 23
  • 42
0

You can use Firebase Analytics by Google to track these app events.

Quang Vĩnh Hà
  • 494
  • 3
  • 8