Code example for WeakReference

Methods: get

0
    private final AQuery aq;
 
    private final WeakReference<Context> contextReference;
 
    public LastfmGetArtistImages(Context context) {
        contextReference = new WeakReference<Context>(context);
 
        // Initiate AQuery 
        aq = new AQuery(contextReference.get());
    } 
 
    @Override 
    protected String doInBackground(String... artistname) {
        if (ApolloUtils.isOnline(contextReference.get()) && artistname[0] != null) {
            try { 
                artist = Artist.getImages(artistname[0], 1, 1, LASTFM_API_KEY);
                Iterator<Image> iterator = artist.getPageResults().iterator();
                while (iterator.hasNext()) {
                    Image mTemp = iterator.next();
                    url = mTemp.getImageURL(ImageSize.LARGESQUARE);
                }