aintshy / android

Android App
Other
7 stars 1 forks source link

Fix communicate Activity and AsyncTask #28

Open BruSD opened 10 years ago

BruSD commented 10 years ago

First of all don't call to view on onPostExecute from any asynk

 @Override
    public void onPostExecute(final Map<Integer, Message> messages) {
        final ListView list = ListView.class.cast(
            this.home.findViewById(R.id.messages)
        );
        final ListAdapter adapter = list.getAdapter();
        final int max = Collections.max(messages.keySet());
        UpdateMessages.Target.class.cast(adapter).update(
            messages, max >= this.last
        );
    }

this.home -is Activity so you can have crash app when you get Incoming call for example

Best way to comunicate betven AsynkTask and Activity is use BroadcastReceiver or use calbak.

fast fix of this bug is check are activity is visible and not null

http://developer.android.com/reference/android/app/Activity.html#hasWindowFocus()

 @Override
    public void onPostExecute(final Map<Integer, Message> messages) {
    if(this.home.hasWindowFocus && this.home != null)   {
        final ListView list = ListView.class.cast(
            this.home.findViewById(R.id.messages)
        );
        final ListAdapter adapter = list.getAdapter();
        final int max = Collections.max(messages.keySet());
        UpdateMessages.Target.class.cast(adapter).update(
            messages, max >= this.last
        );
     }
    }

I can provide more clear solution if you want, but they need more work from you to implement BroadcastReceiver, or you can use my fast fix

karato commented 10 years ago

I'll find a developer for the task soon...

karato commented 10 years ago

Thanks for the ticket, your account was topped up with 15 mins, payment ID 45107751

karato commented 10 years ago

@yegor256 the task is yours

yegor256 commented 9 years ago

@karato please assign someone else here

karato commented 9 years ago

@karato please assign someone else here

@yegor256 -30 points to your rating :(

karato commented 9 years ago

@karato please assign someone else here

@yegor256 got it, someone else will be assigned soon