Hi.
I'm trying to initialize OpenFeint in my game like this:
-----------------------------------------------------------------------------
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
OpenFeintSettings settings = new OpenFeintSettings("xxx",
"xxx","xxx","xxx");
OpenFeint.initialize(this, settings, new OpenFeintDelegate() {});
........................
-----------------------------------------------------------------------------
Result:
1. OpenFeint initialization sometimes take so song(network actions?).
It blocks the main thread.
2. My application remains in onCreate() for too long.
3. My Dev Phone One display ANR(application not responding) dialog
prompting me to choose between 'Force Close' and 'Wait'
4. Soon after that, OpenFeint has done its things and my game shows up
behind the dialog.
5. Now pressing 'Wait' will dismiss the ANR dialog and I can continue
my game properly.
But obviously we don't want ANR dialog. So now I put it in a Thread
like this:
-----------------------------------------------------------------------------
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new Thread(){
@Override
public void run() {
Looper.prepare();
OpenFeintSettings settings = new
OpenFeintSettings("xxx",
"xxx","xxx","xxx");
OpenFeint.initialize(this,
settings, new OpenFeintDelegate() {});
Looper.loop();
}
}.start();
-----------------------------------------------------------------------------
Result: Problem solved. Everything seems to run fine now.
I put Looper.prepare() there because my game will crash if I don't.
The log message told me to put it there.
I put Looper.loop(); there because OpenFeint will not initialize
at all if I don't.
I've read the doc about Looper but honestly I don't understand what
the doc says.
Question:
Question 1. The doc also tell me this:
-------------------------------------------------
public static final void loop ()
Since: API Level 1
Run the message queue in this thread. Be sure to call quit() to end
the loop.
--------------------------------------------------
Can anyone explain when & where should I call quit()?
Question 2 What will happen if I don't call Looper.quit()?
Question 3 Let me ask this straight. Am I taking the correct approach?
Is there some kind of loop running alongside my game all the time if I
do this?
Thank you in advance!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en