0

I am trying to retrieve values from a column in SQLite table and store it in an array. I have to start that activity from a another activity by clicking a button. But unfortunately, when I click that button, I am getting KeyDisplatchTimedOut error, which stopped my application unexpectedly.

This is my logcat -

09-21 01:35:54.379: E/ActivityManager(1226): ANR in com.example.fromstart (com.example.fromstart/.Dialog)
09-21 01:35:54.379: E/ActivityManager(1226): Reason: keyDispatchingTimedOut
09-21 01:35:54.379: E/ActivityManager(1226): Load: 0.79 / 0.61 / 0.6
09-21 01:35:54.379: E/ActivityManager(1226): CPU usage from 5274ms to 0ms ago:
09-21 01:35:54.379: E/ActivityManager(1226):   94% 18598/com.example.fromstart: 93% user + 1.3% kernel
09-21 01:35:54.379: E/ActivityManager(1226):   1.8% 961/adbd: 0.1% user + 1.7% kernel / faults: 491 minor
09-21 01:35:54.379: E/ActivityManager(1226):   1.5% 951/surfaceflinger: 0.3% user + 1.1% kernel
09-21 01:35:54.379: E/ActivityManager(1226):   0.5% 1226/system_server: 0.1% user + 0.3% kernel / faults: 8 minor
09-21 01:35:54.379: E/ActivityManager(1226):   0% 943/yaffs-bg-1: 0% user + 0% kernel
09-21 01:35:54.379: E/ActivityManager(1226): 100% TOTAL: 94% user + 3.7% kernel + 1.3% softirq
09-21 01:35:54.379: E/ActivityManager(1226): CPU usage from 684ms to 1225ms later:
09-21 01:35:54.379: E/ActivityManager(1226):   96% 18598/com.example.fromstart: 96% user + 0% kernel
09-21 01:35:54.379: E/ActivityManager(1226):     96% 18598/ample.fromstart: 96% user + 0% kernel
09-21 01:35:54.379: E/ActivityManager(1226):   3.7% 1226/system_server: 0% user + 3.7% kernel
09-21 01:35:54.379: E/ActivityManager(1226):     3.7% 1243/ActivityManager: 0% user + 3.7% kernel
09-21 01:35:54.379: E/ActivityManager(1226): 100% TOTAL: 94% user + 5.4% kernel
09-21 01:35:54.409: D/dalvikvm(1226): GC_FOR_ALLOC freed 162K, 32% free 7658K/11216K, paused 11ms, total 11ms
09-21 01:35:54.419: I/dalvikvm-heap(1226): Grow heap (frag case) to 8.748MB for 1127532-byte allocation
09-21 01:35:54.459: D/dalvikvm(1226): GC_FOR_ALLOC freed <1K, 29% free 8759K/12320K, paused 42ms, total 42ms
09-21 01:35:54.589: D/(1226): HostConnection::get() New Host Connection established 0xb8579720, tid 1243
09-21 01:36:02.879: W/ActivityManager(1226): Activity destroy timeout for ActivityRecord{b174f320 u0 com.example.fromstart/.MainActivity}

This is the way I am calling that activity -

activity1.java:

alert_menu = (Button) findViewById(R.id.alert_menu);
            alert_menu.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Intent i = new Intent(settings.this,Dialog.class);
                        startActivity(i);
                    }
                }); 

Dialog.java:

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_dup);

for(int i =1;i<=info.getrowcountofpersons();i++) 
{
    items[i-1]=info.getPersonList(i); //this method will return each person name and will be stored in items[] array
    System.out.println("The list items are:"+items[i-1]); 
    Toast.makeText(getApplicationContext(), items[i-1], Toast.LENGTH_LONG).show();

}
}

But instead of doing for loop, and initializing the array as private String[] items = {"Warrior","Archer","Wizard"};, the dialog is shown up and I am not getting that error. What might be the problem here?

Thanks in advance.

nki
  • 192
  • 3
  • 17

1 Answers1

0

I think you are click the button within retrieving data from sqlite process completed. So you have to wait until the process completed. Its better to use AsyncTask to retrieve data from SQLite. For more detail refer this thread.

Community
  • 1
  • 1
Gunaseelan
  • 14,415
  • 11
  • 80
  • 128
  • Hi @Gunaseelan, Thank you for the reply. I have tried AsyncTask as per your suggestion. But also I am getting the same error. Can you please provide me some sample code, if possible? – nki Sep 21 '13 at 06:40