Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[Q] Detect when a new window is shown

OP elesbb

27th July 2014, 01:04 AM   |  #1  
elesbb's Avatar
OP Senior Member
Thanks Meter: 4,468
 
6,922 posts
Join Date:Joined: Jun 2010
Donate to Me
More
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!
28th July 2014, 10:15 PM   |  #2  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,337
 
5,911 posts
Join Date:Joined: Aug 2012
More
Can't you simply hook onResume or similar?
The Following User Says Thank You to GermainZ For This Useful Post: [ View ]
29th July 2014, 12:05 AM   |  #3  
defim's Avatar
Senior Member
Thanks Meter: 933
 
1,797 posts
Join Date:Joined: Feb 2012
Quote:
Originally Posted by GermainZ

Can't you simply hook onResume or similar?

Only one problem left: "super" access -> http://forum.xda-developers.com/xpos...thods-t2822375
The Following User Says Thank You to defim For This Useful Post: [ View ]
29th July 2014, 12:18 AM   |  #4  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,337
 
5,911 posts
Join Date:Joined: Aug 2012
More
Quote:
Originally Posted by defim

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: [ View ]
29th July 2014, 12:24 AM   |  #5  
defim's Avatar
Senior Member
Thanks Meter: 933
 
1,797 posts
Join Date:Joined: Feb 2012
Quote:
Originally Posted by GermainZ

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
The Following User Says Thank You to defim For This Useful Post: [ View ]
29th July 2014, 12:33 AM   |  #6  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 7,337
 
5,911 posts
Join Date:Joined: Aug 2012
More
Quote:
Originally Posted by defim

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: [ View ]
29th July 2014, 03:03 AM   |  #7  
defim's Avatar
Senior Member
Thanks Meter: 933
 
1,797 posts
Join Date:Joined: Feb 2012
Quote:
Originally Posted by GermainZ

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
The Following User Says Thank You to defim For This Useful Post: [ View ]
30th July 2014, 01:44 AM   |  #8  
elesbb's Avatar
OP Senior Member
Thanks Meter: 4,468
 
6,922 posts
Join Date:Joined: Jun 2010
Donate to Me
More
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!

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes