0

I have an application with a navigation bar to transition between different screens of the app. Some of these screens are simple and can be displayed easily with a fragment while the others require me to pull data from a server and populate fields or a list view depending on the screen.

Should I use a mix of fragments and activities based on the needs of each screen? Using fragments is nice because the transition of the screen isn't really noticeable whereas starting a new activity is. Is there some information on best practices for a situation when I have information asynchronously being downloaded while the activity is starting? I would prefer to avoid using a fragment for this situation since the fragment will be displayed and the information/list view will be populated after the screen is shown.

  • In my understanding, Both fragment and activity will have same issue if they are displayed before Async call to get data comes after display. I have similar situation in my App and i rely on local sqllite DB to store information downloaded earlier. If async process completes first then it will anyway show fresh data else user will see the data once they come back to this screen again. Not sure if this helps. – Sachiin Gupta Oct 04 '16 at 19:26
  • @SachiinGupta It sorta helps. The issue is two of my screens are search screens so I can't pre-download the data beforehand. – Brandon Tru Oct 04 '16 at 19:41

2 Answers2

0

I use fragments when I use NavigationDrawer in my Application to download data and show list or whatever kind of layout. You can use AsyncTask in fragment also to download data and display them.

Secondly, how could you know which menu is going to be selected by user to download data before creating the fragment. It's very OK showing loading screen or something like progress bar to download data and populate into fragment.

Dushyant Suthar
  • 673
  • 2
  • 9
  • 27
-2

You have a few options:

1) Use the Bundle from the Intent:

Intent mIntent = new Intent(this, Example.class);
Bundle extras = mIntent.getExtras();
extras.putString(key, value); 

2) Create a new Bundle

Intent mIntent = new Intent(this, Example.class);
Bundle mBundle = new Bundle();
mBundle.putString(key, value);
mIntent.putExtras(mBundle);

3) Use the putExtra() shortcut method of the Intent

Intent mIntent = new Intent(this, Example.class);
mIntent.putExtra(key, value);
  • Sorry I may not have been clear with what I was looking for. Is it acceptable to use Activities when navigating the app via the navigation bar at the bottom of the screen or is there a way to use Fragments without there being delayed information popping up on the screen when the downloads finish? – Brandon Tru Oct 04 '16 at 19:11