HOW TO SEND VALUE FROM ONE CLASS INTO DIFFERENT CLASSES(MORE THAN ONE CLASS)

Jeet Verma

Total Post:110

Points:776
Posted by  Jeet Verma
Java 
 870  View(s)
Ratings:
Rate this:
Hi Everyone!

I have value strUser and KEY ,I want to send this value to multiple different classes because this value will be used in 5 classes for url, I know the way to send value to one class only using Intent.putExtra as bellow :

Intent policy= new Intent(LoginActivity.this,EpolicyListPolis.class);
        policy.putExtra("etUser",strUser);
        policy.putExtra("key",KEY);
        startActivity(policy);
How can I send this value to multiple different classes at a time? can i use SharedPrefences..? how the way i write sharedPrefences in class and my destination class?

Thanks in advance! 
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: how to send value from one class into different classes(more than one class)

    Hi Jeet!


    Try as following

    send value from this class with Intent....

    Intent policy= new Intent(LoginActivity.this,EpolicyListPolis.class);
        policy.putExtra("key",strUser);
        startActivity(policy);

    this works like: KEY-"key" and VALUE-strUser. and you get this value from another class using KEY.

    Get value like this.

    String user = getIntent().getExtras().getString("key",null);
    in user you get strUser value. and if strUser not pass any value than default null(right side of "key") assign for user....

    same you use from all class you need... but remember all works with KEY...

    because KEY(one type of ID) is only which is works to Put and Get particular value.....

    I hope  it helpful for you!

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!