简体   繁体   中英

Pass String from activity to library class

I trying to pass a string from mainActivity to the activity of a library i been trying using intent but is not recognizing this function has someone done this before?

I get this error: error

getIntent is a method that is not available in your OFAndroid Class. If you want to access the Intent that was passes to an Activity you should call It from inside an Activity's Class.

create the OFAndroid class like this

public class OFAndroid {

 private String text ;
 public OFAndroid(String text) { 
  this.text = text ; 
 } 


 public void useText() {
   Log.e("TAG" , this.text);
 }
}

Inside your MainActivity instantiate OFAndroid :

OFAndroid of = new OFAndroid("some string");

now you can use the passed String

of.useText();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM