Android - AsyncTask Is A Beauty - Part 2

Here goes the second part of a short tutorial of how beautiful AsyncTask is, the first tutorial is here. Now that we’re moving up to our second activity which is Hacktivate, a brief description about it is that this activity essentially puts all the data retrieved previously and populate a custom layout ListView. To make reading and understanding easier, here are the codes first before anything else. package com.bango.acerid; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.jsoup.Jsoup; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.os.AsyncTask; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener; public class Hacktivate extends Activity { private String jsonStr = ""; private JSONObject json; private List images = new ArrayList(); private List titles = new ArrayList(); private List writers = new ArrayList(); private List dates = new ArrayList(); private List links = new ArrayList(); private List body = new ArrayList(); private List description = new ArrayList(); private ArticleAdapter adapter = new ArticleAdapter(); private List l = new ArrayList(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.hacktivate); Bundle the = getIntent().getExtras(); jsonStr = (the != null) ? the.getString("listData") : ""; parseJson(jsonStr); ListView articleList = (ListView) findViewById(R.id.list); articleList.setAdapter(adapter); final Intent i = new Intent(this, PostViewer.class); articleList.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { i.putExtra("wvUrl", links.get(position)); i.putExtra("wvBody", body.get(position)); Hacktivate.this.startActivity(i); } }); } private void parseJson(String j) { try { json = new JSONObject(j); JSONArray rss = json.getJSONArray("rss"); int max = rss.length(); for(int i=0; i...

May 26, 2011 · Batista Harahap

Android - AsyncTask Is A Beauty - Part 1

Since last weekend, I’ve been coding more on Android and although the topic about AsyncTask is nothing new, I just wanna bring it up again to appreciate its simplicity and more importantly in real world usable best practice. So I decided to create an RSS client from FeedBurner and this time to get feeds from AcerID.com. The application basically loads all the feeds with its first Activity, show it with the second activity and another helper Activity to send direct emails for questions related with Acer products. Do mind the layout, it’s quite plain but it’s usable nonetheless. So before going on with the tutorial, I’m gonna show some screenshots from and MDPI emulator running Eclair and XHDPI emulator running HoneyComb. ...

May 26, 2011 · Batista Harahap