View.getLocationInWindow() only returns Y (and sometimes not even X)

by Romain Guy » Fri, 29 Jan 2010 06:52:52 GMT


Sponsored Links
 You are probably calling getLocationInWindow() before the layout happened.



>



View.getLocationInWindow() only returns Y (and sometimes not even X)

by ClarkBattle » Fri, 29 Jan 2010 06:53:19 GMT


 Sorry, in that first example I meant;

Log.i("Where?","x=" + loc[0] + " y=" + loc[1] );

not

Log.i("Where?","x=" + where[0] + " y=" + where[1] );

Copy/paste user error :)

--


Sponsored Links


View.getLocationInWindow() only returns Y (and sometimes not even X)

by ClarkBattle » Fri, 29 Jan 2010 06:54:38 GMT


 But its in onStart() while the layout happens in onCreate().  There is
no onFinishInflate() for Activities.  How do i make sure that the
inflation has happened?




> >



Other Threads

1. Problems with background activities or partial locks or something completely altogether?!

It looks like the output you posted is from your custom log file, so
the first thing I'd do is to look at the system log to make sure that
the problem isn't in your custom logging code.
Also, doing anything lengthy in a broadcast receiver is a Bad Idea,
and keeping the device awake while you're doing it is a Really, Really
Bad Idea. If you need to do something every 30 minutes, you should
schedule an alarm, not sleep for 30 minutes with a wakelock held.






--~--~---------~--~----~------------~-------~--~----~

2. Problems with background activities or partial locks or something completely altogether?!

Hi,

  I don't really know how to phrase my question as I don't know what the
problem is. The symptom is that scheduled background activities are not
completed and I want to know why that is and how I can further debug/solve
it.

  This is happening with NewsRob and the background synchronization that
loads articles from Google Reader at a scheduled interval. To debug it I
meanwhile created a synthetic sample that shows the behavior too. A Thread
is started once an hour, acquires a partial wake lock, logs something,
sleeps for 30 minutes and then releases the partial wake lock and logs
again.


  So it should look something like this:
28 04:02: onReceive
28 04:02: In aquire
28 04:32: After release

  28 being the day of the month followed by the time and message.

  Unfortunately it doesn't look like that all the time ;-)  (Blank Lines and
<comment> added for readability).

28 05:02: onReceive
28 05:02: In aquire
28 05:32: After release

28 06:02: onReceive
28 06:02: In aquire
<After release missing>

28 07:02: onReceive
28 07:02: In aquire
<After release missing>

28 08:02: onReceive
28 08:02: In aquire
<After release missing>

28 09:02: onReceive
<In aquire missing>
<After release missing>
....

  So I suspect I do something wrong with the partial wake lock? But what?
And even if that is the case what should happen then? Shouldn't it continue
to run when a button on the device is pressed?

  So here is the full sample code: http://pastie.org/403831

  And here is the relevant method:

    public void onReceive(final Context context, Intent intent) {
        PersistentLog.log("onReceive", context);
        new Thread(new Runnable(){

            public void run() {
                PowerManager pm = (PowerManager)
context.getSystemService(Context.POWER_SERVICE);
                PowerManager.WakeLock wl =
pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SomeTag");
                wl.acquire();
                PersistentLog.log("In aquire", context);
                SystemClock.sleep(30 * 60 * 1000);
                wl.release();
                PersistentLog.log("After release", context);

            }
        }).start();
    }

  Any ideas?

Cheers,
Mariano

ps. Yes, I've seen the typo. Thanks for not bringing it up ;)

--~--~---------~--~----~------------~-------~--~----~

3. nested scopes

4. Most accurate method of using SoundPool

5. The Linked In Google Android group (1700+) is open to Android fans!

6. Dalvik native libraries thread-safe?

7. Starting a new Activity