Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,810,194 Members 52,507 Now Online
XDA Developers Android and Mobile Development Forum

[Q] Using variables between packages

Tip us?
 
rbox
Old
#1  
Senior Member - OP
Thanks Meter 233
Posts: 286
Join Date: Apr 2011

 
DONATE TO ME
Default [Q] Using variables between packages

I am hooking into 2 different packages in my handleLoadPackage and I have a private static variable in the enclosing class. When handleLoadPackage gets called for the first package, I set the private static variable and log it and it looks fine. When handleLoadPackage gets called for the second package, I try to log the private static variable and it's not set. This is directly in handleLoadPackage and not inside any hooks. Is what I'm trying to do not possible because of the calling contexts? How do I share information between hooked functions between multiple packages?
 
GermainZ
Old
#2  
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,401
Posts: 5,478
Join Date: Aug 2012
The problem is that you basically have two different variables, not one — a different one for each package. When you update the variable in package A, the variable in package B is untouched.

You'll need to communicate between the two packages somehow, using e..g a BroadcastReceiver.
 
rbox
Old
#3  
Senior Member - OP
Thanks Meter 233
Posts: 286
Join Date: Apr 2011

 
DONATE TO ME
Quote:
Originally Posted by GermainZ View Post
The problem is that you basically have two different variables, not one a different one for each package. When you update the variable in package A, the variable in package B is untouched.

You'll need to communicate between the two packages somehow, using e..g a BroadcastReceiver.
Thanks. After I posted this and thought about it for a while I came to this conclusion. Each package runs in it's own address space and the handleLoadPackage runs in it's context.
Thread Tools
Display Modes