Dette indlæg er på engelsk fordi jeg sender til flere grupper....

I've made a small app. where I use some sound effects the app. crashes
after I've been into option and clicks the go

back button.

I've added a Prefs  class as described in Ed Burnettes book:
-----------------------------------

package com.example.helloandroid;

import android.content.Context;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;

public class Prefs extends PreferenceActivity
{
  // Option names
  private static final String  OPT_SOUND     = "sound";
  private static final boolean OPT_SOUND_DEF = true;

  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);
  }

  public static boolean getSound(Context context)
  {
    return PreferenceManager.getDefaultSharedPreferences(context).
      getBoolean(OPT_SOUND, OPT_SOUND_DEF);
  }
}

I've made the settings.xml:
-----------------------------------

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
  xmlns:android="http://schemas.android.com/apk/res/android";>
  <CheckBoxPreference
    android:key="sound"
    android:title="@string/sound_title"
    android:summary="@string/sound_summary"
    android:defaultValue="true" />
</PreferenceScreen>


I've created an activity for it:
-----------------------------------

  <activity android:name=".Prefs"
    android:label="@string/settings_title">
  </activity>


I've opened it in the menu handler:
-----------------------------------

  case R.id.settings:
    startActivity(new Intent(this, Prefs.class));
    return true;


And it gives me the 'App stopped
unexpectedly' dialogue. Here's the
logcat:
-----------------------------------

I/ARMAssembler(   52): generated
scanline__00000177:03515104_00000A01_00000000 [
 46 ipp] (70 ins) at [0x283360:0x283478] in 791545 ns
I/Number one(  183): Opening Settings
I/ActivityManager(   52): Starting activity: Intent
{ cmp=com.example.helloandro
id/.Prefs }
I/Number one(  183): Returning from Settings
D/PhoneWindow(  183): couldn't save which view has focus because the
focused vie
w com.example.helloandroid.helloandroid$pa...@43770458 has no id.
D/        (  183): unable to unlink '/data/data/
com.example.helloandroid/shared_
prefs/com.example.helloandroid_preferences.xml.bak': No such file or
directory (
errno=2)
I/ActivityManager(   52): Displayed activity
com.example.helloandroid/.Prefs: 87
9 ms (total 879 ms)
D/AndroidRuntime(  183): Shutting down VM
W/dalvikvm(  183): threadid=3: thread exiting with uncaught exception
(group=0x4
001aa28)
E/AndroidRuntime(  183): Uncaught handler: thread main exiting due to
uncaught e
xception
E/AndroidRuntime(  183): java.lang.IllegalThreadStateException: Thread
already s
tarted.
E/AndroidRuntime(  183):        at java.lang.Thread.start(Thread.java:
1286)
E/AndroidRuntime(  183):        at
com.example.helloandroid.HelloAndroid$Panel.s
urfaceCreated(HelloAndroid.java:193)
E/AndroidRuntime(  183):        at
android.view.SurfaceView.updateWindow(Surface
View.java:392)
E/AndroidRuntime(  183):        at
android.view.SurfaceView.onWindowVisibilityCh
anged(SurfaceView.java:182)
E/AndroidRuntime(  183):        at
android.view.View.dispatchWindowVisibilityCha
nged(View.java:3745)
E/AndroidRuntime(  183):        at
android.view.ViewGroup.dispatchWindowVisibili
tyChanged(ViewGroup.java:690)
E/AndroidRuntime(  183):        at
android.view.ViewGroup.dispatchWindowVisibili
tyChanged(ViewGroup.java:690)
E/AndroidRuntime(  183):        at
android.view.ViewRoot.performTraversals(ViewR
oot.java:694)
E/AndroidRuntime(  183):        at
android.view.ViewRoot.handleMessage(ViewRoot.
java:1613)
E/AndroidRuntime(  183):        at
android.os.Handler.dispatchMessage(Handler.ja
va:99)
E/AndroidRuntime(  183):        at android.os.Looper.loop(Looper.java:
123)
E/AndroidRuntime(  183):        at
android.app.ActivityThread.main(ActivityThrea
d.java:4203)
E/AndroidRuntime(  183):        at
java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime(  183):        at
java.lang.reflect.Method.invoke(Method.java:5
21)
E/AndroidRuntime(  183):        at com.android.internal.os.ZygoteInit
$MethodAndA
rgsCaller.run(ZygoteInit.java:791)
E/AndroidRuntime(  183):        at
com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:549)
E/AndroidRuntime(  183):        at
dalvik.system.NativeStart.main(Native Method)

I/Process (   52): Sending signal. PID: 183 SIG: 3
I/dalvikvm(  183): threadid=7: reacting to signal 3
I/dalvikvm(  183): Wrote stack trace to '/data/anr/traces.txt'
D/dalvikvm(   52): GC freed 13746 objects / 647808 bytes in 183ms
I/ARMAssembler(   52): generated
scanline__00000077:03515104_00000000_00000000 [
 27 ipp] (41 ins) at [0x1ebbb8:0x1ebc5c] in 7870043 ns
I/ARMAssembler(   52): generated
scanline__00000077:03515104_00001001_00000000 [
 64 ipp] (84 ins) at [0x1ebc60:0x1ebdb0] in 2053210 ns
W/ActivityManager(   52): Launch timeout has expired, giving up wake
lock!
W/ActivityManager(   52): Activity idle timeout for
HistoryRecord{4391abd0 com.e
xample.helloandroid/.HelloAndroid}
W/ActivityManager(   52): Activity destroy timeout for
HistoryRecord{43941108 co
m.example.helloandroid/.Prefs}
D/dalvikvm(  101): GC freed 3342 objects / 186512 bytes in 122ms

Strangely enough there's no crash if
I apply a dialog theme to the activity:
-----------------------------------

  <activity android:name=".Prefs"
    android:label="@string/settings_title"
    android:theme="@android:style/Theme.Dialog">
  </activity>


Ideas anyone?

-- 
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

Reply via email to