1

I need to develop an Android app with the following screens to be achieved:

  1. Login Activity (here on click of Login button, need to call a web service which fetches list of huge data from server for 3 different products say, A, B and C, probably in 3 separate ArrayLists)

  2. List Activity (here I need to display the ArrayLists' data in 3 different tabs for A, B & C)

  3. Details Activity (after clicking on any particular list item in any tab A/B/C - the details of that particular item should be displayed)

What is the best way to achieve the 2nd point? Can we render all the tabs data at the same time - because I don't want to start new web request on click of other tabs.

Could you guys please help me.

1 Answers1

0

My solution

1-Singleton to keep 1 istance of your data 2-Service store data in singleton 3-In onCreateView of Fragments keep data from singleton ad display data

This is my solution for your 2nd point

For 3rd point, you can implement serializable in your object and pass it with an intent from your listActivity to your DetailActivity (in listActivity it's easy get the object in Array by position)

EDIT

SINGLETON

public class GlobalVarSingleton {
private static final String TAG = "GlobalVarSingleton";
private static GlobalVarSingleton mInstance = null;

    private static myObj token;

    private GlobalVarSingleton(){

    }

    public static GlobalVarSingleton getInstance(Context ctx){
        if(mInstance == null)
        {
            Log.d(TAG, "init Global Singleton");
            mInstance = new GlobalVarSingleton(); 
        }
        return mInstance;
    }

    public void setData(myObj data){
        this.token = data;
    }

    public myObj getData(){
        return token;
    }
}

To access -> GlobalVarSingleton.getIstance(context).setData(data); (or getData...) this allow you to have a single istance of your object in app. The best it's init this Singleton in Application class

public class MyApplication extends Application {

@Override
public void onCreate()
{
    super.onCreate();
    GlobalVarSingleton.getInstance(this);
}
}

So in Service you just need call setData it as up and pass your data just getted. myObj is a sample, you must use your data object offcourse.

In CreateView with GlobalVarSingleton.getIstance(this.getActivity()).getData(); you get data storaged

For serializable look it Passing data through intent using Serializable

Note, it's important that you know when data is available, I think that you wait web response to load new listActivity, is it right?

ABOUT APPLICATION CLASS http://developer.android.com/reference/android/app/Application.html

Community
  • 1
  • 1
Ivan
  • 978
  • 6
  • 13
  • Thanks Iwen for your quick response. Can you provide me some pointers (sample code) or links to achieve this 1st and 2nd. 3rd one I got it. – Rama Krishna Jan 10 '15 at 20:26
  • Thank you again iwen - much appreciated. And yes - I am thinking to wait for the web service response to load the list activity in tab fragments. Actually I need to call 2 web services - one for checking login authentication, and the other for getting list data. Generally what would be the best way - to call 2 web services after click of 'Login' button in LoginActivity (or) call just login web service on click of 'Login' button and call the second web service on ListActivity loading or something? – Rama Krishna Jan 11 '15 at 03:13
  • There is a lot off solutions to do it. I think the best is call login web call and when you will get The response call The second web call. On The response off second call show activity. Call login and data web call at the same time isn't right because I think that you want show data only if user is registred . – Ivan Jan 11 '15 at 10:43