I am implementing a thread like the following. Is my implementation correct?
It works well, but I need a check.
myList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, final View view,
int position, long id) {
// TODO Auto-generated method stub
Runnable runnable = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Looper.prepare();
Context context = view.getContext();
final String titleItem = (String) ((TextView) view.findViewById(R.id.titleItem)).getText();
final String descItem = (String) ((TextView) view.findViewById(R.id.descItem)).getText();
final Bitmap bitmap = (Bitmap) ((BitmapDrawable) ((ImageView) view.findViewById(R.id.imgItem)).getDrawable()).getBitmap();
Toast.makeText(context, "Item Title: " + titleItem + ", Item Desc: " + descItem, Toast.LENGTH_SHORT).show();
myHandler.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Intent intent = new Intent(getApplicationContext(), ItemDetails.class);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bytes = stream.toByteArray();
intent.putExtra("title", titleItem);
intent.putExtra("BMP",bytes);
intent.putExtra("desc", descItem);
Log.i("ON ITEM CLICK", "OK");
startActivity(intent);
}
});
Looper.loop();
}
};
new Thread(runnable).start();
stopThread(Thread.currentThread());
}
});
Can you please tell me if you see something wrong or if there is a better way of doing the same or to optimize it?