get variable out of class?

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

get variable out of class?

Postby The Spirit » Tue Jan 13, 2009 6:41 pm

Hi.
I use

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         public BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
  2.  
  3.                
  4.  
  5.                 @Override
  6.  
  7.                 public void onReceive(Context context, Intent intent) {
  8.  
  9.                        
  10.  
  11.                         Integer f = intent.getIntExtra("level", 0);
  12.  
  13.                        
  14.  
  15.                 }
  16.  
  17.         };
Parsed in 0.030 seconds, using GeSHi 1.0.8.4

in order to read the battery level.
Now i want to use f, which indicates the battery level as an integer value, in another function and class.
How can i "get out" the variable f from this class?
Tried to us a public variable, but therefore f needs to be static and runs in a conflect with onReceive.
Any ideas?
Thanks
The Spirit
Developer
Developer
 
Posts: 48
Joined: Fri Jan 02, 2009 1:59 pm
Location: Germany

Top

Postby MrSnowflake » Tue Jan 13, 2009 7:03 pm

Give some more info about the situation.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby The Spirit » Tue Jan 13, 2009 7:10 pm

in need the variable f in
puclic void Sampleview extends View {
in the function
onDraw
in order to calculate the size of a rectangle
The Spirit
Developer
Developer
 
Posts: 48
Joined: Fri Jan 02, 2009 1:59 pm
Location: Germany

Postby MrSnowflake » Tue Jan 13, 2009 7:14 pm

As your BroadcastReceiver is a member of the View (I guess) you can use fields from the View.
No offence, but that's basic Java...
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby The Spirit » Tue Jan 13, 2009 7:40 pm

thanks for info.
startet java about two weeks ago.
have done python for a long time until now
The Spirit
Developer
Developer
 
Posts: 48
Joined: Fri Jan 02, 2009 1:59 pm
Location: Germany

Postby MrSnowflake » Tue Jan 13, 2009 8:59 pm

The Spirit wrote:thanks for info.
startet java about two weeks ago.
That explains :).

The Spirit wrote:have done python for a long time until now
Though the same practice should go for phyton too...
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests