Your keyboard is not responding because displayResult is displayResult in your main ui displayResult .
One possible solution to handle this problem correctly is to use an IntentService , for example, you can:
MyIntentService.java
public class MyIntentService extends IntentService {
Basically, you have a Service that retrieves data in a background thread and sends data to your Activity when some kind of event (start / end) occurs.
In your Activity class, you need to do the following:
1. Declare an instance of BroadcastReceiver :
private BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if(intent.hasExtra("resultCode")) { int resultCode = intent.getIntExtra("resultCode",MyService.STATUS_ERROR); switch (resultCode) { case MyIntentService.RESULT_START: showIndeterminateProgress(); break; case MyIntentService.RESULT_ENDED: updateResultList(data); break; case MyIntentService.RESULT_ERROR: showErrorMessage(); break; } } } };
2. Register and unregister BroadcastReceiver :
@Override public void onResume(){ super.onResume(); registerReceiver(mReceiver, new IntentFilter(MyIntentService.SERVICE_BROADCAST)); } @Override public void onPause() { super.onPause(); unregisterReceiver(mReceiver); }
3. Start the service:
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { if (!newText.trim().equals("")) { Intent i = new Intent(this, MyIntentService.class); i.putExtra("MyQuery",newText); startService(i); return false; } } });
Sources:
source share