1

I have created an application with firestore database. When user logged in or registered in application, firebase device token will be add as a field in database. At the time of logout i have put the code of delete instanceid and token too. Still i am receiving notification of previous user after logout. Here is my code.

On Registration Page:

private fun addNewUser(uid: String, socialUser: FirebaseUser? = null) {
  FirebaseInstanceId.getInstance().instanceId.addOnSuccessListener(activity, OnSuccessListener<InstanceIdResult> { instanceIdResult ->
        val mToken = instanceIdResult.token
        userModel.deviceToken = mToken
    })
  val mapData = userModel.getMap()
   database.collection(UserModel.COLLECTION_APP_USERS).document(uid).set(mapData, SetOptions.merge())
            .addOnSuccessListener { _: Void? ->
                UserTokenManager(activity).setUserMe(userModel)
                isSignInSuccessful.value = ApiResponse(true)
            }
            .addOnFailureListener { exception: Exception ->
                isSignInSuccessful.value = ApiResponse(exception)
            }

}

So here i am adding token id in firestore database.

Now following code on logout.

fun endSession() {
    try {
        val sharedPreferenceHelper = SharedPreferenceHelper(context)
        FirebaseAuth.getInstance().signOut()
        FirebaseInstanceId.getInstance().deleteInstanceId()
        FirebaseInstanceId.getInstance().deleteToken("7398260350" , "FCM")
        SharedPreferenceHelper(context).clearAll()
        val intent = Intent(this, SignInActivity::class.java)
        startActivity(intent)
        finish()
       } catch (e: Exception) {
        Log.e("exception", "==->${e.message}")
   }
}

Still i am receiving notifications after logout.

Keval Shukla
  • 437
  • 6
  • 18
  • I don't see the `deleteInstanceId()` call. There's the `deleteToken()` but that only works for different (non-default) senders. – AL. Oct 08 '18 at 12:10
  • @AL i have added code for deleting instanceid and test the application. Still i am receiving notifications. – Keval Shukla Oct 08 '18 at 12:24
  • I think it will be easier if you save a boolean flag in local db(or in shared preferences), and after logout remove it, and every time you are showing push notification, you can check whether the flag is true or not, if (flag){//show push} – Rob Oct 08 '18 at 12:43
  • How are you sending the notifications? Is it via topics? – AL. Oct 08 '18 at 13:42
  • Yes it is topic wise @AL. – Keval Shukla Oct 08 '18 at 13:51
  • Are you resubscribing when `onNewToken()` gets called? – AL. Oct 08 '18 at 14:33

0 Answers0