Rajesh Rajesh - 11 days ago 5
Android Question

How to know if application data is cleared or application is uninstalled?

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.

Answer

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.

Comments