Access Variables from Another Class

Put your problem here if it does not fit any of the other categories.

Access Variables from Another Class

Postby auser12 » Sat Feb 11, 2012 2:35 am

Hi everyone. I have a class called SingleTouchView.java which runs as my main class. In this class when the user touches the screen, a network operation tries to run, but an error occurs saying that a network operation cannot be run on the main class. So I created a new class called Client.java and put the network operation on there. Now, when the user touches the screen, it runs the Client class. But the problem is I need to use two variables in the Client class that were created in the SingleTouchView class, and I cannot access them. Is it possible to access them through the Client class? I hope I did not make this too confusing. Thanks for your help!

The SingleTouchView class extends the View object, if that helps any.
auser12
Freshman
Freshman
 
Posts: 8
Joined: Sun Feb 05, 2012 12:38 am

Top

Re: Access Variables from Another Class

Postby Phyll » Sat Feb 11, 2012 9:23 pm

Hi auser,

If I'm understanding your problem, it seems like you could

1. Send the values for these variables in the constructor for the class.

2. Use application scope global variables that can be accessed anywhere in the applicataion.

3. If Client is an Activity that is started by an Intent, pass them in the extras of the intent mechanism.

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Access Variables from Another Class

Postby auser12 » Sat Feb 11, 2012 11:32 pm

Thanks so much. It works perfectly!
auser12
Freshman
Freshman
 
Posts: 8
Joined: Sun Feb 05, 2012 12:38 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 27 guests