Skip to content Skip to sidebar Skip to footer

Sending Token And Id To Server

I am trying to develop a webview app that uses JSinterface to get the user_id. what I am trying to do is send two values to my server, user_id and FCM token,onpause(). i am getting

Solution 1:

try to make one class for updating and getting value from your default sharedpreference, this will help you avoid confusion:

publicclasssharedpref {
    
        privateSharedPreferences mysharedpref;
    
        publicsharedpref(Context cntx) { // pass context of activity you are using this
          
            mysharedpref = PreferenceManager.getDefaultSharedPreferences(cntx);
        }
    
        publicvoidsetuserid(String userid) {
            prefs.edit().putString("userid", userid).commit();
        }
     publicStringgetuserid(){
            String userid = prefs.getString("userid","");
            return  userid;
        }
      publicvoidsettoken(String token) {
            prefs.edit().putString("token", token).commit();
        }
     publicStringgettoken(){
            String token = prefs.getString("token","");
            return  token;
        }
}

Now in any activity just call:

privatesharedprefsp=newsharedpref(this.getApplicationContext());
// then simply perform your operations

sp.settoken(value);
sp.getuserid();

Post a Comment for "Sending Token And Id To Server"