ece çalıkuş
ece çalıkuş

Reputation: 139

how to send a parameter an activity class to a normal class?

in my project i am using voice recognition. i want to take the result of that class and pass it another class. But because this class is not an activity class, i cant use intent. the codes i use in voice recognition are like that:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

     if (requestCode == REQUEST_CODE && resultCode == RESULT_OK){
         ArrayList<String> matches = new ArrayList<String>();
    matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);


    if(matches.size()>0)  {
         result = matches.get(0);}}

I want to take that result and use another class which is not an activity class. So please help me

Upvotes: 1

Views: 499

Answers (3)

Lalit Poptani
Lalit Poptani

Reputation: 67296

You can declare you ArrayList as a static one like this,

public static ArrayList<String> array = new ArrayList<String>(); 

By doing this you can access your ArrayList from anywhere by

activity_name.array;

where activity_name is the activity or class in which you declare the static ArrayList

Upvotes: 0

Paresh Mayani
Paresh Mayani

Reputation: 128448

you can define the setters/getters inside that normal class. Later on, retrieve the value by using that setter method of that class through object.

Upvotes: 0

Vineet Shukla
Vineet Shukla

Reputation: 24031

You need to save the data. For this you can use SQlite, SharedPreference or static variable..

Upvotes: 0

Related Questions