So here's the deal..
I have a...
public class HomeActivity extends ActionBarActivity implements ActionBar.TabListener
and two fragments which are a part of the tabs of HomeActivity:
public class Fragment1 extends Fragment
and
public class Fragment2 extends Fragment
Here's the code that adds those fragments to the tabs:
list = new ArrayList<Fragment>();
list.add(Fragment1.newInstance("SomeString"));
Extra Info: Fragment1 has an AsyncTask that downloads the JSON data, parses it into an ArrayList and passes it to the Activity via an Interface.
Then the adapter is called and it uses its methods like getItem() and getPosition() etc... and adds them. Now clearly, there's no fragmentTransaction()
used, thus, we cannot set any tags or IDs.
Now the android documentation says that you need to getFragmentById()
OR getFragmentByTag()
and then call the fragment's someUpdatingMethod()
to update the fragment via the Activity.
MY QUESTION:
this someUpdatingMethod() basically needs to go through an arrayList of customObjects, retrieve information and add markers onto GoogleMap. This needs to be done in UI thread. Should I just call the typical
new Handler(Looper.getMainLooper()).post(new Runnable(){
@Override
public void run() {
//Add markers Code Goes Here....
}});
Or is there a better way to do it?
P.S.: I'm not looking to 'just get the work done', because yes it is working. I'm trying to find out the best practices. Thank u very much!