Asynchronous Android by 2013

Asynchronous Android by 2013

Author:2013
Language: eng
Format: mobi, epub
Publisher: Packt Publishing


Finally, we need to implement onCanceled to clean up any data that might be loaded in the background after a cancellation has been issued:

@Override public void onCanceled(Bitmap data) { if (data != null) data.recycle(); }

Depending on the kind of data Loader produces, we may not need to worry about cleaning up the result of canceled work—ordinary Java objects will be cleaned up by the garbage collector when they are no longer referenced.

Bitmap, however, can be a tricky beast—older versions of Android store the bitmap data in native memory, outside of the normal object heap, requiring a call to recycle to avoid potential OutOfMemoryErrors.

So far so good—we have a Loader. Now we need to connect it to a client Activity or Fragment. We know that our Activity is going to load an image from an ID reference, and that it will need somewhere to display that image. Let's get these easy bits out of the way first:

public class ThumbnailActivity extends Activity { private Integer mediaId; private ImageView thumb; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.thumb); thumb = (ImageView) findViewById(R.id.thumb); mediaId = getMediaIdFromIntent(getIntent()); } }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.