Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass variable between non-activity class to android activity class

I need to pass a variable from (around)non-activity class to an nameget(android activity)class . Display the passed variable value in text view.. Please tel me what needs to do from this example. How to pass it to android activity

public class around(non-activity class)
{
    String name = "arjun";
    //how to pass this name value to an below activity
    nameget nam = new nameget();
    String new = nam.get(name);
}

public class nameget extends Activity(android activity class)
{
   public String get(String name)
   {
      String got = name;
      TextView t1 = (TextView)findViewById(R.id.textView1);
      t1.setText(name);
    }
}
like image 289
Aruva Avatar asked Feb 12 '13 09:02

Aruva


2 Answers

Try this, declare your non activity class in you activity class.

 public class around(non-activity class)
{
Public static String name;
 name = "arjun";
//how to pass this name string to an below activity
}

 public class nameget extends Activity(android activity class)
  {
  around ar = new around();
  //declare non activity class here

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
TextView t1 = (TextView)findViewById(R.id.textView1);
t1.setText(ar.name);
 }
 }
like image 184
MuraliGanesan Avatar answered Sep 18 '22 23:09

MuraliGanesan


Try this

  public class around(non-activity class)
    {
     public static  String name = "arjun";
        //how to pass this name string to an below activity
    }

    public class nameget extends Activity(android activity class)
    {
        TextView t1 = (TextView)findViewById(R.id.textView1);
//your class name around
        t1.setText(around.name);
    }
like image 38
Yogesh Tatwal Avatar answered Sep 19 '22 23:09

Yogesh Tatwal