-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StrongReference of AsyncTask #25
Comments
I may be wrong but since the class is initialized into an object it doesn't matter that it's an inner class. Just like before, once the async task ends then it's object will be disposed. If the activity is disposed before that it is also fine. Are you new to Java by any chance? You sound like a C programmer :-D If you are interesting in contributing to the project I can send you a few stack traces from the Play console. I haven't had much time to work on this project in the last year or so. It could use some love. |
Maybe you misunderstood what I mean. The cancel operation of AsyncTask doesn't really destroy the background thread. It just change the status of AsyncTask to cancelled. And if the status of AsyncTask is cancelled, then onCancelled instead of onPostExecute will be invoked. If you didn't cancel it, then there might be problems if onPostExecute is invoked to update the UI while Activity has been destroyed. Of course, maybe you still want to invoke onPostExecute even the Activity is destroyed. If it is that case, then there won't be problem if you don't cancel AsyncTask.
By the way, I'm not new to Java. In fact, I have written Java since I was a postgraduate student.
…------------------ 原始邮件 ------------------
发件人: "micwallace"<[email protected]>;
发送时间: 2019年8月14日(星期三) 晚上6:36
收件人: "micwallace/reddinator"<[email protected]>;
抄送: "潘临杰"<[email protected]>;"Author"<[email protected]>;
主题: Re: [micwallace/reddinator] StrongReference of AsyncTask (#25)
I may be wrong but since the class is initialized into an object it doesn't matter that it's an inner class. Just like before, once the async task ends then it's object will be disposed. If the activity is disposed before that it is also fine.
Are you new to Java by any chance? You sound like a C programmer :-D
If you are interesting in contributing to the project I can send you a few stack traces from the Play console. I haven't had much time to work on this project in the last year or so. It could use some love.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I think I intend to run post execute in most cases, although I haven't had a look at the code in a while. There should definitely be a null check on any activity context references. If you think it could be improved please feel free to submit a pull request.
…On 14 August 2019 10:22:37 pm AEST, Linjie Pan ***@***.***> wrote:
Maybe you misunderstood what I mean. The cancel operation of AsyncTask
doesn't really destroy the background thread. It just change the status
of AsyncTask to cancelled. And if the status of AsyncTask is cancelled,
then onCancelled instead of onPostExecute will be invoked. If you
didn't cancel it, then there might be problems if onPostExecute is
invoked to update the UI while Activity has been destroyed. Of course,
maybe you still want to invoke onPostExecute even the Activity is
destroyed. If it is that case, then there won't be problem if you don't
cancel AsyncTask.>
>
>
By the way, I'm not new to Java. In fact, I have written Java since I
was a postgraduate student.>
>
>
>
>
------------------ 原始邮件 ------------------>
发件人: ***@***.***>;>
发送时间: 2019年8月14日(星期三) 晚上6:36>
收件人: ***@***.***>;>
抄送: ***@***.******@***.***>;>
主题: Re: [micwallace/reddinator] StrongReference of AsyncTask (#25)>
>
>
>
>
I may be wrong but since the class is initialized into an object it
doesn't matter that it's an inner class. Just like before, once the
async task ends then it's object will be disposed. If the activity is
disposed before that it is also fine.>
>
Are you new to Java by any chance? You sound like a C programmer :-D>
>
If you are interesting in contributing to the project I can send you a
few stack traces from the Play console. I haven't had much time to work
on this project in the last year or so. It could use some love.>
>
—>
You are receiving this because you authored the thread.>
Reply to this email directly, view it on GitHub, or mute the thread.>
>
-- >
You are receiving this because you commented.>
Reply to this email directly or view it on GitHub:>
#25 (comment)
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
au.com.wallaceit.reddinator.activity.ViewAllSubredditsActivity.DLTask is an inner class of au.com.wallaceit.reddinator.activity.ViewAllSubredditsActivity, which means The AsyncTask class holds strong reference to the Activity. In other words, there is a potential memory leak danger.
I think DLTask should be changed to a static class or outter class. Thank you.
The text was updated successfully, but these errors were encountered: