Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing Intent data from Activity to Class

Tags:

string

android

I want to pass string from my activity class to my class that is not extended to activity. I know this is possible but how to do that? I am new to android development so please help

like image 362
Multi Modal Avatar asked Mar 04 '26 07:03

Multi Modal


1 Answers

In android you can send data through Intent or Intent followed by Bundle like:

Intent i = new Intent(current_activity.this, linked_class.class);
i.putextra("Key", value);

And get the value(suppose string value) in another class like:

String value = getIntent.getExtra("String key which you used when send value");

Option 2:

class yourClass {
public static String _utfValue = "";
void sendValue(){
   _utfValue  = "some value";
}
}

And fetch this value in your java class like:

String value = A._utfValue ;

Option 3: You can use SharedPreference to save the value and get it from other class.

Option 4: You can use a static method with some return value and fetch the method in your java class through class name.

All the options are rough here. So just check this ,hope one of these will help you .


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!