Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,804,353 Members 40,535 Now Online
XDA Developers Android and Mobile Development Forum

[Q] Detect when a new window is shown

Tip us?
 
elesbb
Old
#1  
elesbb's Avatar
Senior Member - OP
Thanks Meter 4,365
Posts: 6,792
Join Date: Jun 2010

 
DONATE TO ME
Default [Q] Detect when a new window is shown

Hey guys.

I am trying to figure out when a new app is shown. I have tried hooking into the Activity class for onWindowFocusedChanged method which works under normal conditions.

For instance, my ROM has the ability to hold a button to kill foreground app. Works great. however, doing that, the onWindowFocusedChanged method is not called. So my module does not detect the focus is lost.

I am wondering if anyone else has any other ideas. AccessibilityService works perfectly. But uses a lot of CPU and other resources. Was thinking maybe Window.class or WindowManager.class would help as well. But not sure. Thanks guys for your time!
 
GermainZ
Old
#2  
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,353
Posts: 5,447
Join Date: Aug 2012
Can't you simply hook onResume or similar?
The Following User Says Thank You to GermainZ For This Useful Post: [ Click to Expand ]
 
defim
Old
#3  
Senior Member
Thanks Meter 799
Posts: 1,548
Join Date: Feb 2012
Quote:
Originally Posted by GermainZ View Post
Can't you simply hook onResume or similar?
Only one problem left: "super" access -> http://forum.xda-developers.com/xpos...thods-t2822375
Motorola Defy+ aka MB526 Android 4.4.4 Cyanogen Mod
Samsung S4a aka GT-i9295 Android 4.2.2 Google Edition
My Android apps / Xposed modules: show Threads
The Following User Says Thank You to defim For This Useful Post: [ Click to Expand ]
 
GermainZ
Old
#4  
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,353
Posts: 5,447
Join Date: Aug 2012
Quote:
Originally Posted by defim View Post
Only one problem left: "super" access -> http://forum.xda-developers.com/xpos...thods-t2822375
I don't see how that is related in this case. Why would he want to call the super method explicitly?
The Following User Says Thank You to GermainZ For This Useful Post: [ Click to Expand ]
 
defim
Old
#5  
Senior Member
Thanks Meter 799
Posts: 1,548
Join Date: Feb 2012
Quote:
Originally Posted by GermainZ View Post
I don't see how that is related in this case. Why would he want to call the super method explicitly?
eg for onResume the 1st call have to be super.onResume
Motorola Defy+ aka MB526 Android 4.4.4 Cyanogen Mod
Samsung S4a aka GT-i9295 Android 4.2.2 Google Edition
My Android apps / Xposed modules: show Threads
The Following User Says Thank You to defim For This Useful Post: [ Click to Expand ]
 
GermainZ
Old
#6  
GermainZ's Avatar
Forum Moderator / Recognized Developer
Thanks Meter 6,353
Posts: 5,447
Join Date: Aug 2012
Quote:
Originally Posted by defim View Post
eg for onResume the 1st call have to be super.onResume
There's no reason to use beforeHookedMethod/replaceHookedMethod in this case, so the original method will call the super method, and afterHookedMethod can be used to e.g. send a broadcast without having to worry about it.
The Following User Says Thank You to GermainZ For This Useful Post: [ Click to Expand ]
 
defim
Old
#7  
Senior Member
Thanks Meter 799
Posts: 1,548
Join Date: Feb 2012
Quote:
Originally Posted by GermainZ View Post
There's no reason to use beforeHookedMethod/replaceHookedMethod in this case, so the original method will call the super method, and afterHookedMethod can be used to e.g. send a broadcast without having to worry about it.
Yeas, with afterHookedMethod no problems, but i wanted to point to that, so he has not to do the same research as me
Motorola Defy+ aka MB526 Android 4.4.4 Cyanogen Mod
Samsung S4a aka GT-i9295 Android 4.2.2 Google Edition
My Android apps / Xposed modules: show Threads
The Following User Says Thank You to defim For This Useful Post: [ Click to Expand ]
 
elesbb
Old
#8  
elesbb's Avatar
Senior Member - OP
Thanks Meter 4,365
Posts: 6,792
Join Date: Jun 2010

 
DONATE TO ME
Thanks guys for your reply!

I did end up using an AccessibilityService. After much reading and testing, i have gotten the app to use .04 percent of the CPU in the last 5 hours. Pretty damn good! I am probably going to use this method anyhow.

I did hook onResume and onCreate, but some nothing would happen when some apps would show. For instance, the home screen of Apex launcher wouldn't trigger on onResume or anything like that. I even looked at the smali and it uses a LauncherActivity which extends the Activity class. So I was awfully confused. I tried it with both a before and after hooked method. I surely thought hooking onResume and onCreate would signify the opening of an app. But it didn't for all of them.

Thanks again for your replies!

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes