SHOW:
|
|
- or go back to the newest paste.
1 | public class MyFragment extends Fragment { | |
2 | ||
3 | TextView textView; | |
4 | ||
5 | @Override | |
6 | public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
7 | Bundle savedInstanceState) { | |
8 | View v = inflater.inflate(R.layout.activity_main, null); | |
9 | textView = (TextView) v.findViewById(R.id.textview); | |
10 | new LeakTask().execute(); | |
11 | return v; | |
12 | } | |
13 | ||
14 | private class LeakTask extends AsyncTask<Void, Integer, Void> { | |
15 | @Override | |
16 | protected Void doInBackground(Void... params) { | |
17 | for (int i = 0; i < 50; i++) { | |
18 | - | publishProgress(); |
18 | + | publishProgress(i); |
19 | } | |
20 | return null; | |
21 | } | |
22 | ||
23 | @Override | |
24 | protected void onProgressUpdate(Integer... values) { | |
25 | super.onProgressUpdate(values); | |
26 | textView.append(String.valueOf(values[0])); | |
27 | } | |
28 | } | |
29 | ||
30 | @Override | |
31 | public void onDestroyView() { | |
32 | super.onDestroyView(); | |
33 | textView = null; // settings this here null, might cause a nullpointer | |
34 | // in onProgressUpdate | |
35 | // textView.append(String.valueOf(values[0])); | |
36 | ||
37 | } | |
38 | } |