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. Thoughts on this LenientPolicy implementation of an LVL Policy?

I've been playing around with the new LVL announced yesterday and
wanted to write a policy which only stops the user when it is certain
that he does not have a license.

In other words, the policy will only "dontAllow" the user if the last
meaningful response from the licensing service was NOT_LICENSED.
Therefore, if the user is offline when they first use the app, then
they will be allowed in.

The idea behind this is that I don't want genuine paying users to ever
(within reason) be inconvenienced by this licensing system.

The downside is that all the user needs to do is clear the app data
and go offline before restarting the app. The app will continue
working until they go online (and restart the app).

My thoughts are:

1. Most users won't know about that workaround
2. Those users that are happy to use that workaround, probably
wouldn't pay for the app anyway

Any other thoughts?

===

Here is the code:

public void processServerResponse(LicenseResponse response,
ResponseData rawData) {
        mLastResponse = response;
        if (response == LicenseResponse.LICENSED || response ==
LicenseResponse.NOT_LICENSED) {
                // note - we don't want to say "IS_LICENSED" because that can be
hacked
                SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(this.mContext);
                Editor edit = prefs.edit();
                if (response == LicenseResponse.LICENSED) {
                        edit.remove(NOT_LICENSED_PREF);
                } else if (response == LicenseResponse.NOT_LICENSED) {
                        edit.putBoolean(NOT_LICENSED_PREF, true);
                }
                edit.commit();
        }
}

public boolean allowAccess() {
        if (mLastResponse == null) {
                // this is the first call
                return false;
        }
        switch (mLastResponse) {
        case LICENSED:
                return true;
        case NOT_LICENSED:
                return false;
        default:
                return !isDefinitelyNotLicensed();
        }
}

public boolean isDefinitelyNotLicensed() {
        // if we don't know, then its NOT definitely not licensed.
        SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(mContext);
        return prefs.getBoolean(NOT_LICENSED_PREF, false);
}

-- 

2. I'm done with development, how do i publish my apk

Hi,

I'm just about done with development and emulator testing and I'm
unclear how to proceed with getting my application ready for actual
device testing and them publishing.

Here's my main concern: I have around 600 images that I will need to
have loaded (on initial installation) onto an sd card.  What is the
best way to do this? HTTP? Is there an automated process? Is this
handled by an installation script.

Are there documents that cover this type of scenario?

When it comes time for actual publishing the application, again, how
will I handle loading the images onto the sd card during the initial
installation?

Thanks,

jb

-- 

3. hadi sunarpo ingin chatting

4. WTHelp : Droid setelah instal CM 6 RC 2 gak bisa masuk recovery clockwork

5. Any way to get notified when startActivity is called?

6. What is the URI for the Contacts content provider on Samsung phones? ActivityNotFoundException:

7. I would like to be able to buy an app for a friend