General task state detection & handling

by Grant » Thu, 14 Oct 2010 01:34:56 GMT


Sponsored Links
 In my current application (a game) I'm currently having problems
determining when to pause my audio. Pretty much the entire game runs
in a single Activity (basically a wrapper around some JNI code) so
changing between game states is irrelevant. My main problems come from
the key-lock screen and a 3rd party library which I use for leader-
boards and the like.

Previously I would pause/resume the audio whenever the appliction had
'onWindowFocusChanged' called which handled the key-lock screen as
expected. Unfortunately this had the side effect of causing
'AlertDialog' dialogs to cut out the audio when displayed.
Subsequently, I changed it to pause/resume audio in the 'onPause' and
'onResume' functions of the Activity. This works well except the sound
will continue to play when the key-lock screen is up. Is there any way
for me to detect when the key-lock screen gets displayed (apart from
constantly polling) and pause the sound when this occurs?

My other problem is that when I start the activity for the 3rd party
library (it actually starts it self after it establishes a network
connection), my audio stops playing (as the game's activity goes to
the background and gets "paused"). How can I detect when the entire
task/application goes to the background?

Thanks,
Grant

--



Other Threads

1. Need Help Dream!!!

Hi,
my name is Serena and I'm writing from Italy.
I have a G1 brad Tim Italia, 2 days ago I installed RC7...and now my
phone now is T-Mobile and has problem with keyboard, and I cant'use
Telnet.
Beside my pc don't see the phone in fastboot, and when i try to
install something the phone give me this message:"E:cant'open /cache/
recovery/command", or "No signature" ora something like this.
When I Holding the side camera button + power I have only a rainbow
screen and I can't do anything :(

Please could you help me?

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

2. problem in <include> tag in relative layout xml files

Hi,
I was trying to use "include" tag in a RelativeLayout as follows:

---------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/toolbar_divider1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/toolbar_item_gap"
android:src="@drawable/menu_divider">
</ImageView>

<include android:id="@+id/mnubtn_new_email"
layout="@layout/text_rightof_icon"
android:layout_toRightOf="@id/toolbar_divider1"/>

</RelativeLayout>
---------------------------------------------------------------------------
Where text_rightof_icon layout xml is as follows:

---------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/text_icon_bottom_margin"
        />

        <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:layout_toRightOf="@id/icon"
        />

</RelativeLayout>
---------------------------------------------------------------------------

So my expectation was that the included layout text_rightof_icon will
be placed on the right edge of toolbar_divider1.  But
text_rightof_icon  actually overlaps toolbar_divider1.
toolbar_divider1's image and text is set in code after inflating it in
code and using findviewbyid() to get its reference.  Everything works
fine except the layout.  Any idea why?  Now instead of using include I
am actually adding content of  text_rightof_icon  in all places which
is making my xml file very large and afraid that it will be hard to
maintain later.

Thanking in advance,
regards,
Ari

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

3. ClassNotFoundException

4. Read inbox SMS

5. Question about getFileStreamPath

6. Open source and diagramming

7. Android App Widgets