Example usage for android.os Handler Handler

List of usage examples for android.os Handler Handler

Introduction

In this page you can find the example usage for android.os Handler Handler.

Prototype

public Handler() 

Source Link

Document

Default constructor associates this handler with the Looper for the current thread.

Usage

From source file:com.mycelium.wallet.simplex.SimplexMainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.simplex_main_activity);

    _walletAddress = getIntent().getExtras().getString("walletAddress");
    _activityHandler = new Handler();
    //display the loading spinner
    setLayout(SimplexUITypes.Loading);/*from   ww  w . jav  a 2s  .co m*/

    Button retryButton = (Button) findViewById(R.id.btSimplexRetry);
    retryButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setLayout(SimplexUITypes.Loading);
            simplexAsync.run();
        }
    });

    //simplex app auth
    simplexAsync.run();
}

From source file:com.facebook.android.Places.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mHandler = new Handler();
    location = new JSONObject();

    setContentView(R.layout.places_list);

    Bundle extras = getIntent().getExtras();
    String default_or_new = extras.getString("LOCATION");
    if (default_or_new.equals("times_square")) {
        try {/*from  w w  w  .  j  a v a 2 s . c  om*/
            location.put("latitude", new Double(TIMES_SQUARE_LAT));
            location.put("longitude", new Double(TIMES_SQUARE_LON));
        } catch (JSONException e) {
        }
        fetchPlaces();
    } else {
        getLocation();
    }
}

From source file:mad.codeforcommunity.CalendarView.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.calendar);// w  w  w .jav a  2 s .  c  o  m
    month = Calendar.getInstance();
    //  onNewIntent(getIntent());

    items = new ArrayList<String>();
    adapter = new CalendarAdapter(this, month);

    GridView gridview = (GridView) findViewById(R.id.gridview);
    gridview.setAdapter(adapter);

    handler = new Handler();
    handler.post(calendarUpdater);

    TextView title = (TextView) findViewById(R.id.title);
    title.setText(android.text.format.DateFormat.format("MMMM yyyy", month));

    TextView previous = (TextView) findViewById(R.id.previous);
    previous.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            if (month.get(Calendar.MONTH) == month.getActualMinimum(Calendar.MONTH)) {
                month.set((month.get(Calendar.YEAR) - 1), month.getActualMaximum(Calendar.MONTH), 1);
            } else {
                month.set(Calendar.MONTH, month.get(Calendar.MONTH) - 1);
            }
            refreshCalendar();
        }
    });

    TextView next = (TextView) findViewById(R.id.next);
    next.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            if (month.get(Calendar.MONTH) == month.getActualMaximum(Calendar.MONTH)) {
                month.set((month.get(Calendar.YEAR) + 1), month.getActualMinimum(Calendar.MONTH), 1);
            } else {
                month.set(Calendar.MONTH, month.get(Calendar.MONTH) + 1);
            }
            refreshCalendar();

        }
    });

    gridview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            TextView date = (TextView) v.findViewById(R.id.date);
            ImageView image = (ImageView) v.findViewById(R.id.date_icon);
            if (date instanceof TextView && !date.getText().equals("")) {
                if (image.getVisibility() == View.VISIBLE) {
                    /*OLD CODE
                     * Intent intent = new Intent();
                    String day = date.getText().toString();
                    if(day.length()==1) {
                       day = "0"+day;
                    }
                    // return chosen date as string format 
                    intent.putExtra("date", android.text.format.DateFormat.format("yyyy-MM", month)+"-"+day);
                    setResult(RESULT_OK, intent);
                    finish();
                    */

                    Bundle extras = new Bundle();
                    String day = date.getText().toString();
                    if (day.length() == 1) {
                        day = "0" + day;
                    }
                    // return chosen date as string format 
                    extras.putString("date",
                            android.text.format.DateFormat.format("yyyy-MM", month) + "-" + day);

                    Intent intent = new Intent(CalendarView.this, EventView.class);
                    intent.putExtras(extras);

                    startActivity(intent);
                }

            }

        }
    });
}

From source file:com.mobilesolutionworks.android.http.WorksHttpFutureTask.java

/**
 * Execute specified works http request in parallel.
 *
 * @param request works http request/*from ww  w. j a  v  a2  s  .co  m*/
 */
public void execute(WorksHttpRequest request) {
    execute(request, new Handler(), WorksHttpExecutor.THREAD_POOL_EXECUTOR);
}

From source file:com.dedipower.portal.android.ColoLanding.java

public void onCreate(Bundle savedInstanceState) {
    API.SessionID = getIntent().getStringExtra("sessionid");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cololanding_iclone);
    //Temp/*  ww w.  j  a v  a2 s .  co m*/
    list = (ListView) findViewById(R.id.ColoCabList);
    final ProgressDialog dialog = ProgressDialog.show(this, "DediPortal", "Please wait: loading data....",
            true);
    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();
            if (Success.equals("true")) {
                UpdateErrorMessage(ErrorMessage);
                ColoRacksAdaptor adapter = new ColoRacksAdaptor(ColoLanding.this, listOfColoRacks);
                list.setAdapter(adapter);
            } else {
                UpdateErrorMessage(ErrorMessage);
            }
        }
    };

    Thread dataPreload = new Thread() {
        public void run() {
            try {
                Colo = API.PortalQuery("colocation", "none");
                Success = Colo.getString("success");
            } catch (JSONException e) {
                ErrorMessage = "An unrecoverable JSON Exception occurred.";
                //UpdateErrorMessage("An unrecoverable JSON Exception occurred.");
            }

            if (Success.equals("false")) {
                try {
                    //UpdateErrorMessage(Colo.getString("msg"));
                    ErrorMessage = Colo.getString("msg");
                } catch (JSONException e) {
                    ErrorMessage = "An unrecoverable JSON Exception occured.";
                    //UpdateErrorMessage("An unrecoverable JSON Exception occured.");
                }
            } else {
                Log.i("APIFuncs", Colo.toString());
                try {
                    ColoCabs = Colo.getJSONArray("colocation");
                    ErrorMessage = "";
                    //UpdateErrorMessage("");
                } catch (JSONException e) {
                    ErrorMessage = "There are no Co-Location Cabinets in your account.";
                    //UpdateErrorMessage("There are no Co-Location Cabinets in your account.");
                }

                int ColoCount = ColoCabs.length();

                if (ColoCount == 0) {
                    //UpdateErrorMessage("There are no colocation cabinets for your account.");
                    ErrorMessage = "There are no colocation cabinets for your account.";
                    handler.sendEmptyMessage(0);
                    return;
                }

                for (int i = 0; i < ColoCount; i++) {
                    JSONObject CurrentColo = null;
                    try {
                        CurrentColo = ColoCabs.getJSONObject(i);
                    } catch (JSONException e1) {
                        Log.e("APIFuncs", e1.getMessage());
                    }

                    try {
                        listOfColoRacks.add(new ColoRacks(CurrentColo.getString("ip"),
                                CurrentColo.getString("servercode"), CurrentColo.getString("facility"),
                                CurrentColo.getInt("bandwidth"), CurrentColo.getString("bandwidthTotal"),
                                CurrentColo.getInt("transferlimit"), CurrentColo.getString("state")));
                    } catch (JSONException e) {
                        Log.e("APIFuncs", e.getMessage());
                    }
                }
            }
            handler.sendEmptyMessage(0);
        }
    };

    dataPreload.start();
    //temp

    /*try 
    {
       Colo = API.PortalQuery("colocation", "none");
      Success = Colo.getString("success");   
    } 
    catch (JSONException e) 
    {
       UpdateErrorMessage("An unrecoverable JSON Exception occured.");
       //Toast.makeText(ColoLanding.this, "An unrecoverable JSON Exception occured.", Toast.LENGTH_LONG).show();
    }
            
    if(Success == "false")
    {
       try 
       {
    UpdateErrorMessage(Colo.getString("msg"));
      } 
       catch (JSONException e) 
       {
     UpdateErrorMessage("An unrecoverable JSON Exception occured.");
      }
    }
    else
    {
       Log.i("APIFuncs",Colo.toString());
       try
        {
      ColoCabs = Colo.getJSONArray("colocation");
      UpdateErrorMessage("");
        }
        catch (JSONException e) 
        {
      UpdateErrorMessage("There are no Co-Location Cabinets in your account.");
        }
                
        //OK lets actually do something useful
        ListView list = (ListView)findViewById(R.id.ColoCabList);
        List<ColoRacks> listOfColoRacks = new ArrayList<ColoRacks>();
        int ColoCount = ColoCabs.length();
                
        if(ColoCount == 0)
        {
      UpdateErrorMessage("There are no colocation cabinets for your account.");
      return;
        }
                
        for(int i = 0; i < ColoCount; i++)
        {
      JSONObject CurrentColo = null;
    try 
    {
       CurrentColo = ColoCabs.getJSONObject(i);
    } 
    catch (JSONException e1) 
    {
       Log.e("APIFuncs",e1.getMessage());
    }
      try 
      {
       listOfColoRacks.add(new ColoRacks(CurrentColo.getString("ip"),
                                 CurrentColo.getString("servercode"),
                                 CurrentColo.getString("facility"), 
                                 CurrentColo.getInt("bandwidth"), 
                                 CurrentColo.getString("bandwidthTotal"), 
                                 CurrentColo.getInt("transferlimit"), 
                                 CurrentColo.getString("state")));
    } 
      catch (JSONException e) 
      {
         Log.e("APIFuncs",e.getMessage());
    }
        }
                
        ColoRacksAdaptor adapter = new ColoRacksAdaptor(this, listOfColoRacks);
                
        list.setAdapter(adapter);
            
    }*/
}

From source file:com.fangyuan.vpngate.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*from   w  ww .  j  a va2  s .com*/

    mContext = this;

    mListView = (ListView) findViewById(R.id.vpn_list);
    mListView.setDividerHeight(16);

    mListItems = new ArrayList<HashMap<String, Object>>();
    SimpleAdapter adapter = new SimpleAdapter(this, mListItems, R.layout.vpn_summary,
            new String[] { "country", "ip" }, new int[] { R.id.country, R.id.ip });
    mListView.setAdapter(adapter);

    hosts = getSharedPreferences("vpngate", MODE_PRIVATE).getString("hosts", null);
    if (hosts != null) {
        parseHostsString(hosts);
    }

    mHandler = new Handler() {
        public void handleMessage(Message msg) {
            hosts = msg.getData().getString("hosts");
            if (hosts != null) {
                if (parseHostsString(hosts)) {
                    SimpleAdapter adapter = (SimpleAdapter) mListView.getAdapter();
                    adapter.notifyDataSetChanged();
                }

            }
            getActionBarHelper().setRefreshActionItemState(false);
        }
    };
}

From source file:com.dedipower.portal.android.CDNLanding.java

public void onCreate(Bundle savedInstanceState) {
    API.SessionID = getIntent().getStringExtra("sessionid");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cdnlanding);

    //Progress test
    list = (ListView) findViewById(R.id.CDNList);
    final ProgressDialog dialog = ProgressDialog.show(this, "DediPortal", "Please wait: loading data....",
            true);//from   w  w w.java2s .c  o  m
    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();
            if (Success.equals("true")) {
                UpdateErrorMessage(ErrorMessage);
                CDNAdaptor adapter = new CDNAdaptor(CDNLanding.this, listOfCDNs);
                list.setAdapter(adapter);
            } else {
                UpdateErrorMessage(ErrorMessage);
            }
        }
    };

    Thread dataPreload = new Thread() {
        public void run() {
            try {
                CDNs = API.PortalQuery("cdn", "none");
                Success = CDNs.getString("success");
            } catch (JSONException e) {
                ErrorMessage = "An unrecoverable JSON Exception occured.";
                //UpdateErrorMessage("An unrecoverable JSON Exception occured.");
            }

            if (Success.equals("false")) {
                try {
                    //UpdateErrorMessage(CDNs.getString("msg"));
                    ErrorMessage = CDNs.getString("msg");
                } catch (JSONException e) {
                    //UpdateErrorMessage("A JSON parsing error prevented an exact error message to be determined.");
                    ErrorMessage = "A JSON parsing error prevented an exact error message to be determined.";
                }
            } else {
                try {
                    CDNNodes = CDNs.getJSONArray("cdns");
                    //UpdateErrorMessage("");
                    ErrorMessage = "";
                } catch (JSONException e) {
                    //UpdateErrorMessage("There are no CDN nodes in your account.");
                    ErrorMessage = "There are no CDN nodes in your account.";
                }
                int CDNCount = CDNNodes.length();

                if (CDNCount == 0) {
                    //UpdateErrorMessage("There are no CDN nodes for your account.");
                    ErrorMessage = "There are no CDN nodes for your account.";
                    Success = "false";
                    handler.sendEmptyMessage(0);
                }

                for (int i = 0; i < CDNCount; i++) {
                    try {
                        CurrentCDN = CDNNodes.getJSONObject(i);
                    } catch (JSONException e1) {
                        Log.e("APIFuncs", e1.getMessage());
                    }

                    listOfCDNs.add(new CDN(GetString("name"), GetString("backend"), GetInt("bandwidthemea"),
                            GetInt("bandwidthapac"), GetInt("bandwidthamericas"), GetBool("loadbalanced")));
                }
            }
            handler.sendEmptyMessage(0);
        }
    };

    dataPreload.start();
    //Progress test

    /*try 
    {
       CDNs = API.PortalQuery("cdn", "none");
      Success = CDNs.getString("success");   
    } 
    catch (JSONException e) 
    {
       UpdateErrorMessage("An unrecoverable JSON Exception occured.");
       //Toast.makeText(ColoLanding.this, "An unrecoverable JSON Exception occured.", Toast.LENGTH_LONG).show();
    }
            
    if(Success == "false")
    {
       try 
       {
    UpdateErrorMessage(CDNs.getString("msg"));
      } 
       catch (JSONException e) 
       {
     UpdateErrorMessage("A JSON parsing error prevented an exact error message to be determined.");
      }
    }
    else
    {
       Log.i("APIFuncs",CDNs.toString());
       try
        {
     CDNNodes = CDNs.getJSONArray("cdns");
      UpdateErrorMessage("");
        }
        catch (JSONException e) 
        {
      UpdateErrorMessage("There are no CDN nodes in your account.");
        }
                
        //OK lets actually do something useful
        ListView list = (ListView)findViewById(R.id.CDNList);
        List<CDN> listOfCDNs = new ArrayList<CDN>();
        int CDNCount = CDNNodes.length();
                
        if(CDNCount == 0)
        {
      UpdateErrorMessage("There are no CDN nodes for your account.");
      return;
        }
                
        for(int i = 0; i < CDNCount; i++)
        {
    try 
    {
       CurrentCDN = CDNNodes.getJSONObject(i);
    } 
    catch (JSONException e1) 
    {
       Log.e("APIFuncs",e1.getMessage());
    }
            
         listOfCDNs.add(new CDN(GetString("name"),
               GetString("backend"),
               GetInt("bandwidthemea"),
               GetInt("bandwidthapac"),
               GetInt("bandwidthamericas"),
               GetBool("loadbalanced")));
        }
            
        CDNAdaptor adapter = new CDNAdaptor(this, listOfCDNs);
                
        list.setAdapter(adapter);
    }*/
}

From source file:net.networksaremadeofstring.pulsant.portal.TicketLanding.java

public void onCreate(Bundle savedInstanceState) {
    API.SessionID = getIntent().getStringExtra("sessionid");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ticketlanding);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("Tickets");

    final ListView list = (ListView) findViewById(R.id.TicketList);

    final ProgressDialog dialog = ProgressDialog.show(this, "Pulsant Portal",
            "Please wait: loading tickets....", true);
    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();/*from   w  w  w  . ja v  a2  s  .co m*/
            if (Success.equals("true")) {
                UpdateErrorMessage(ErrorMessage);
                OpenTicketsAdaptor adapter = new OpenTicketsAdaptor(TicketLanding.this, listOfTickets,
                        API.SessionID);
                list.setAdapter(adapter);
            } else {
                UpdateErrorMessage(ErrorMessage);
            }
        }
    };

    Thread dataPreload = new Thread() {
        public void run() {
            try {
                TicketAPI = API.PortalQuery("tickets", "none");
                Success = TicketAPI.getString("success");
            } catch (JSONException e) {
                ErrorMessage = "An unrecoverable JSON Exception occured.";
                Success = "false";
            }

            if (Success.equals("false")) {
                try {
                    ErrorMessage = TicketAPI.getString("msg");
                } catch (JSONException e) {
                    ErrorMessage = "A JSON parsing error prevented an exact error message to be determined.";
                }
            } else {
                Log.i("APIFuncs", TicketAPI.toString());
                try {
                    Tickets = TicketAPI.getJSONArray("tickets");
                    ErrorMessage = "";
                } catch (JSONException e) {
                    ErrorMessage = "There are no open tickets for your account.";
                }

                //OK lets actually do something useful
                //ListView list = (ListView)findViewById(R.id.TicketList);
                //List<OpenTickets> listOfTickets = new ArrayList<OpenTickets>();
                int TicketCount = Tickets.length();

                if (TicketCount == 0) {
                    ErrorMessage = "There are no open tickets for your account.";
                    handler.sendEmptyMessage(0);
                    return;
                }

                for (int i = 0; i < TicketCount; i++) {
                    JSONObject CurrentTicket = null;
                    try {
                        CurrentTicket = Tickets.getJSONObject(i);
                    } catch (JSONException e1) {
                        Log.e("APIFuncs", e1.getMessage());
                    }
                    try {
                        listOfTickets.add(new OpenTickets(CurrentTicket.getString("status"),
                                CurrentTicket.getInt("id"), CurrentTicket.getString("server"),
                                CurrentTicket.getString("email"), CurrentTicket.getString("subject"),
                                CurrentTicket.getInt("createdat"), CurrentTicket.getInt("lastupdate"), false));
                        //CurrentTicket.getBoolean("subscriber")));
                    } catch (JSONException e) {
                        Log.e("APIFuncs", e.getMessage());
                    }
                }
            }

            handler.sendEmptyMessage(0);
        }
    };

    dataPreload.start();
}

From source file:com.dedipower.portal.android.Launcher.java

/** Called when the activity is first created. */
@Override/* w w w  .  ja  v a  2  s.  c o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.launcher);

    dialog = new ProgressDialog(this);
    dialog.setMessage("Logging in.....");

    //Get our settings
    settings = getSharedPreferences("Dedipower", 0);
    ManageSettings();

    handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();
            //Apparantly stopping threads is no longer supported
            //peformLogin.stop();

            if (APIResponse == "true") {
                //Tell the user
                Toast.makeText(Launcher.this, "Login Successful", Toast.LENGTH_SHORT).show();

                //Check the "remember details checkbox"
                CheckBox Remember = (CheckBox) findViewById(R.id.RememberDetailsCheckBox);

                SharedPreferences.Editor editor = settings.edit();
                if (Remember.isChecked() == true) {
                    editor.putString("AcctCode", AcctCode);
                    editor.putString("Email", Email);
                    editor.putString("Password", Password);
                    editor.putBoolean("Remember", true);
                    editor.commit();
                } else {
                    editor.putString("AcctCode", "");
                    editor.putString("Email", "");
                    editor.putString("Password", "");
                    editor.putBoolean("Remember", false);
                    editor.commit();
                }

                //Do extent stuff
                Intent LauncherIntent = new Intent(Launcher.this, PortalLanding.class);
                LauncherIntent.putExtra("sessionid", API.SessionID);
                Launcher.this.startActivity(LauncherIntent);
                finish();
            } else {
                Toast.makeText(Launcher.this, "Login Failed: " + APIResponse, Toast.LENGTH_SHORT).show();
            }
        }
    };

    Button LoginButton = (Button) findViewById(R.id.LoginButton);
    LoginButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.show();
            EditText AcctCodeEditText = (EditText) findViewById(R.id.AcctCodeInput);
            EditText EmailEditText = (EditText) findViewById(R.id.EmailInput);
            EditText PasswordEditText = (EditText) findViewById(R.id.PasswordInput);
            AcctCode = AcctCodeEditText.getText().toString();
            Email = EmailEditText.getText().toString();
            Password = PasswordEditText.getText().toString();

            Credentials.add(new BasicNameValuePair("account", AcctCode));
            Credentials.add(new BasicNameValuePair("username", Email));
            Credentials.add(new BasicNameValuePair("password", Password));
            CreateThread();
            peformLogin.start();

            /*String APIResponse = API.Login(Credentials);
            if(APIResponse == "true")
            {
              //Tell the user
              Toast.makeText(Launcher.this, "Login Successful", Toast.LENGTH_SHORT).show();
                      
              //Check the "remember details checkbox"
              CheckBox Remember = (CheckBox) findViewById(R.id.RememberDetailsCheckBox);
                      
              SharedPreferences.Editor editor = settings.edit();
              if(Remember.isChecked() == true)
              {
                editor.putString("AcctCode", AcctCodeEditText.getText().toString());
                editor.putString("Email", EmailEditText.getText().toString());
                editor.putString("Password", PasswordEditText.getText().toString());
                editor.putBoolean("Remember", true);
                editor.commit();
              }
              else
              {
                editor.putString("AcctCode", "");
                editor.putString("Email", "");
                editor.putString("Password", "");
                editor.putBoolean("Remember", false);
                editor.commit();
              }
                      
              //Do extent stuff
              Intent LauncherIntent = new Intent(Launcher.this, PortalLanding.class);
              LauncherIntent.putExtra("sessionid", API.SessionID);
              Launcher.this.startActivity(LauncherIntent);
              finish();
            }
            else
            {
              Toast.makeText(Launcher.this, "Login Failed: " + APIResponse, Toast.LENGTH_SHORT).show();
            }*/
        }
    });
}

From source file:net.networksaremadeofstring.pulsant.portal.InvoiceLanding.java

public void onCreate(Bundle savedInstanceState) {
    API.SessionID = getIntent().getStringExtra("sessionid");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.invoicelanding);
    final ListView list = (ListView) findViewById(R.id.InvoiceList);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("Accounting");

    final ProgressDialog dialog = ProgressDialog.show(this, "Pulsant Portal", "Please wait: loading data....",
            true);/*from   w  w w.j a va  2 s.  c  o m*/
    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();
            if (Success.equals("true")) {
                UpdateErrorMessage(ErrorMessage);
                InvoiceAdaptor adapter = new InvoiceAdaptor(InvoiceLanding.this, listOfInvoices, API.SessionID);
                list.setAdapter(adapter);
            } else {
                UpdateErrorMessage(ErrorMessage);
            }
        }
    };

    Thread dataPreload = new Thread() {
        public void run() {
            try {
                InvoiceAPIReturn = API.PortalQueryHack("invoices", "", "");
                Success = InvoiceAPIReturn.getString("success");
            } catch (JSONException e) {
                ErrorMessage = "An unrecoverable JSON Exception occured.";
                Success = "false";
            }

            if (Success.equals("false")) {
                Log.i("API", "Success was false");
                try {
                    ErrorMessage = InvoiceAPIReturn.getJSONObject("hackReturn").getString("msg");
                } catch (JSONException e) {
                    ErrorMessage = "A JSON parsing error prevented an exact error message to be determined.";
                }
            } else {
                int InvoiceCount = 0;
                Log.i("APIFuncs", InvoiceAPIReturn.toString());
                try {
                    Invoices = InvoiceAPIReturn.getJSONObject("hackReturn").getJSONArray("data");
                    InvoiceCount = Invoices.length();
                    ErrorMessage = "";
                } catch (JSONException e) {
                    ErrorMessage = "There don't appear to be any invoices for your account.....";
                    InvoiceCount = 0;
                    Log.e("API", "There was an eror parsing the array");
                    Log.e("API", e.getMessage());
                }

                //OK lets actually do something useful

                if (InvoiceCount == 0) {
                    Success = "false";
                    ErrorMessage = "There are no invoices for your account.";
                    handler.sendEmptyMessage(0);
                    return;
                }

                for (int i = 0; i < InvoiceCount; i++) {
                    JSONObject CurrentInvoice = null;
                    try {
                        CurrentInvoice = Invoices.getJSONObject(i);
                    } catch (JSONException e1) {
                        Log.e("APIFuncs", e1.getMessage());
                    }
                    try {
                        if (CurrentInvoice.getString("type").equals("invoice")) {
                            listOfInvoices.add(new Invoices(CurrentInvoice.getString("ref"),
                                    CurrentInvoice.getDouble("amount"), CurrentInvoice.getString("details"),
                                    CurrentInvoice.getString("date")));
                        } else {
                            Receipts.add(new Receipts(CurrentInvoice.getString("ref"),
                                    CurrentInvoice.getDouble("amount"), CurrentInvoice.getString("details"),
                                    CurrentInvoice.getString("date")));
                        }
                    } catch (JSONException e) {
                        Log.e("APIFuncs", e.getMessage());
                    }
                }
            }

            handler.sendEmptyMessage(0);
        }
    };

    dataPreload.start();
}