Weird FC from unregisterReceiver

by Karim B » Mon, 03 Jan 2011 16:22:06 GMT


Sponsored Links
 here the sum up of my code  http://pastebin.com/YcPWNYit 

my problem only occurs when my application gets installed over my 
application again(aka when I run it from eclipse) and this only occurs when 
the value of ENABLED_KEY is left true so this fc happens when my the value 
is changed from true to false after I install my app again... this does not 
occur the other way around(false to true) and it also does not occur if I 
manually uninstall my app from the emulator and then install the newer 
version because then the preferences actually get deleted where when I 
install a different version on top of the old the preferences do not 
change... I have a feeling that mReceiver is problem but I can't detect if 
the app is being removed/new version getting installed so how would I 
possibly destroy it? and I might be taking the wrong approach at this... any 
help is appreciated.

thanks

-- 



Re: Weird FC from unregisterReceiver

by Karim B » Wed, 05 Jan 2011 04:01:37 GMT


 bump?

-- 


Sponsored Links


Other Threads

1. ListView setAdapter in onCreate, getChildCount is zero in onStart?

I want to display a ListView with checkboxes, and I want some of the
checkboxes pre-selected.  The ListView has setAdapter called during
onCreate, and the list information appears when the screen is drawn.
However, when I attempt to set certain list items as checked, my
ListView reports getChildCount() = 0.

My SharedPreferences contains a list of sounds that have been
previously selected, as a comma delimited string of list indices.
Because the list appears to have no children in onStart, my attempts
to set items as checked fails.

On the good side, once the list is rendered, I can select entries and
hit Back, and my selection is stored to SharedPreferences correctly.

How can I load my previous selection into the list?  Should I be using
something else here?

In the spirit of open source, here's my code, free to you :)

====================================================
SoundLibrary.Java
====================================================

import java.util.Hashtable;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.SparseBooleanArray;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class SoundLibrary extends Activity{
        ListView lstSounds;
        Hashtable<String, Integer> soundTable;
        CharSequence[] soundNames;
        CharSequence[] soundLocations;
        OnLongClickListener previewListener;
        static Context myContext;
        static MediaPlayer player;
        SharedPreferences prefs;

        @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.soundlibrary);
        myContext = this.getApplicationContext();
        prefs = getSharedPreferences("myAppData", 0);

        soundTable = new Hashtable<String, Integer>();
        LoadSoundTable();
        lstSounds = (ListView)findViewById(R.id.lstSounds);
        PopulateSoundList();
        lstSounds.setOnLongClickListener(new PreviewListener());
        }

        @Override
        public void onStart() {
                super.onStart();
                String[] selectedSoundsArray =
                        prefs.getString("selectedSounds", "").split(",");
                for (int selI = 0; selI < selectedSoundsArray.length; selI++) {
                        if (lstSounds.getChildCount() <= selI) {
                                break;
                        }
                        try {
                                
lstSounds.getChildAt(Integer.parseInt(selectedSoundsArray
[selI])).setSelected(true);
                        } catch (NumberFormatException e) { }
                }
        }

        @Override
        public void onPause() {
                super.onPause();
                StringBuffer sb = new StringBuffer();
                SparseBooleanArray sbaSelectedSounds =
lstSounds.getCheckedItemPositions();
                for (int sbaKey = 0; sbaKey < sbaSelectedSounds.size(); 
sbaKey++)
                {
                        if (sbaSelectedSounds.get(sbaKey, false))
                        {
                                sb.append(String.valueOf(sbaKey));
                                sb.append(',');
                        }
                }
                prefs.edit().putString("selectedSounds", 
sb.toString()).commit();
        }

        private void LoadSoundTable()
        {
                Resources res = getResources();
                CharSequence[] soundNames =
                        res.getTextArray(R.array.sound_name);
                CharSequence[] soundLocations =
                        res.getTextArray(R.array.sound_location);

                for (int i = 0; i < soundNames.length; i++) {
                        soundTable.put(soundNames[i].toString(),
                                        
res.getIdentifier(soundLocations[i].toString(), "raw",
this.getPackageName()));
                }
        }

        private void PopulateSoundList()
        {
        ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
                        android.R.layout.simple_list_item_multiple_choice,
                        soundTable.keySet().toArray(new String[soundTable.keySet
().size()]));
        lstSounds.setAdapter(aa);
        }

        private class PreviewListener extends Activity implements
OnLongClickListener {
                public boolean onLongClick(View v) {
                        String previewSoundName = 
lstSounds.getSelectedItem().toString();
                        player = MediaPlayer.create(myContext,
                                        
soundTable.get(previewSoundName).intValue());
                player.start();
                return true;
                }
        }
}


====================================================
soundlibrary.xml - in res/layout
====================================================

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

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtTitle"
android:text="@string/sound_library_title"></TextView>

<ListView
android:id="@+id/lstSounds"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:choiceMode="multipleChoice"
android:clickable="true"
android:focusable="true"
android:longClickable="true"></ListView>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtPreview"
android:text="@string/sound_library_preview"></TextView>

</LinearLayout>


====================================================
sounds.xml  - in res/values
====================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
        <string-array name="sound_name">
                <item>Big Sound</item>
                <item>Little Sound</item>
        </string-array>
        <string-array name="sound_location">
                <item>test_big_sound</item>
                <item>test_little_sound</item>
        </string-array>
</resources>

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

2. Design Issues

I've been trying to find a way to place some buttons on my custom
view. I did not use ViewGroup, but the need is to place couple buttons
at the high end of y coordinate. I sure don't know if I could use an
XML layout for this. So imagine that 1/10 th or 1/15th of the Y axis
on high end ( i.e. the bottom of the screen ) would be devoted to
those buttons. Rest of the canvas is dynamically drawn figures.

Using programmatic-ally, the drawable object, I can place them
properly, but it is hard to label those buttons with text. I know it
is possible to perhaps create several button with embedded text and
draw them based on the application states, but that seems to be bit of
a work.

Would it be possible to use XML formatted layout to place those
buttons at the high end of Y axis, as well as leave the rest for
custom viewed draw without going through Viewgroup?

Any suggestion
--~--~---------~--~----~------------~-------~--~----~

3. Can't find documentation on end-user FW upgrade process

4. Publish Apps for Other Developers

5. Can't find documentation on end-user FW upgrade process

6. OOM error caught bei DefaultException handler ... but there is plenty of memory

7. Doubt