-3

I am making a music player application on android. My Launcher Activity(MainActivity.java) displays all the songs in a Custom ListView. My app was running perfectly and then I decided to add a SearchView widget in the ToolBar. Now when I type a query in the SearchView, me Searchable.java activity opens up and after 2-3 sconds the whole screen turns black. The search results are shown for a brief time but the black screen stays there permanently. If don't use the search option then the application shows no such behavior.

Community
  • 1
  • 1

1 Answers1

1

Your app displaying black screen because you are doing search operations on your main thread , that's why your main thread hanging , check your log monitor you will get error like , too much work on main thread , for overcome this issue you need to perform your search operations on another thread or in background and update your view when search completed , you can use Asynctask for background task .

Rajesh Koshti
  • 572
  • 1
  • 7
  • 25
  • would using a fragment resolve the issue? – Prakhar Singh Jan 20 '17 at 07:47
  • just put your search query for getting audio data list in asynctask it will handle automatically all the things check this out for more details https://developer.android.com/reference/android/os/AsyncTask.html – Rajesh Koshti Jan 20 '17 at 09:12
  • So i was reading the link and I wanted to ask that since the operation to be performed is Searching, should I place the execute() method call inside onCreateOptionsMenu() method? – Prakhar Singh Jan 20 '17 at 16:08