Android Search Filter Implementation

Let's say you are showing a list of movies.

You are suggesting the filter (as a separate activity) (The filter window can be overlaid on top of the movie list (not sure how I can do this in android)

Now the user selects filters on the filter screen and wants to apply the filter.

The filter data should be carried over from the filter activity to the previous activity (which shows movie lists).

How do I pass data in this scenario?

Should I use any event system (like NotificationCenter in ios)? Or should I use some form startActivity

even if the activity is already running and waiting.

+3


source to share


2 answers


  • If you want to open a specific Activity

    one to get the result in the previous one Activity

    , the best practice for me is to use startActivityForResult(intent,requestCode)

    instead startActivity(intent)

    .

  • Override the following method is your first activity where you want to receive data onActivityResult(int requestCode, int resultCode, Intent data)

  • To return the result to the 1st operation, the following code must be run in the 2nd operation

            Intent resultIntent = new Intent();
            resultIntent.putExtra("data", yourData); //make 'yourData' Serializable if a POJO
            setResult(Activity.RESULT_OK, resultIntent);
            finish();
    
          

  • After running this code, you will get a callback in onActivityResult()

    in your first activity where you called startActivityForResult()

    with whatever extars

    you put. Hope this helps. GL



+1


source


Implement the interface Runnable

and add the UI changes you want to make inside the method run

. Then create an instance and send it to the main UIThread using runOnUiThread . Then your changes will take place in the main activity (where you have a list of movies).



An example of how to use runOnUiThread .

0


source







All Articles