[FTF] Sony Xperia Z Lollipop Release

Sony rolled out a Lollipop update for Xperia Z just yesterday. If you still haven’t gotten … more

Original Moto G Receives Lollipop, OTA Captured

The original Moto G was released almost two years ago. Motorola still continues to … more

Device Review: No.1 X1 Rugged Smartphone

We are almost at the end of Q2 for 2015, and we have seen most of the flagship phones for the … more

When a Friend or Family Member Asks for a Phone Recommendation, What Do You Tell Them?

The majority of us here at XDA would consider … more
Post Reply Subscribe to Thread Email Thread

[Q] Detect when a new window is shown

27th July 2014, 12:04 AM |#1  
elesbb's Avatar
OP Senior Member
Thanks Meter: 4,670
 
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, 09:15 PM |#2  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 8,221
 
More
Can't you simply hook onResume or similar?
The Following User Says Thank You to GermainZ For This Useful Post: [ View ]
28th July 2014, 11:05 PM |#3  
defim's Avatar
Senior Member
Thanks Meter: 1,081
 
More
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 ]
28th July 2014, 11:18 PM |#4  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 8,221
 
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 ]
28th July 2014, 11:24 PM |#5  
defim's Avatar
Senior Member
Thanks Meter: 1,081
 
More
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 ]
28th July 2014, 11:33 PM |#6  
GermainZ's Avatar
Forum Moderator / Recognized Developer / XDA Portal Team
Thanks Meter: 8,221
 
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, 02:03 AM |#7  
defim's Avatar
Senior Member
Thanks Meter: 1,081
 
More
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, 12:44 AM |#8  
elesbb's Avatar
OP Senior Member
Thanks Meter: 4,670
 
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