Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyFragment extends Fragment {
- TextView textView;
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View v = inflater.inflate(R.layout.activity_main, null);
- textView = (TextView) v.findViewById(R.id.textview);
- new LeakTask().execute();
- return v;
- }
- private class LeakTask extends AsyncTask<Void, Integer, Void> {
- @Override
- protected Void doInBackground(Void... params) {
- for (int i = 0; i < 50; i++) {
- publishProgress(i);
- }
- return null;
- }
- @Override
- protected void onProgressUpdate(Integer... values) {
- super.onProgressUpdate(values);
- textView.append(String.valueOf(values[0]));
- }
- }
- @Override
- public void onDestroyView() {
- super.onDestroyView();
- textView = null; // settings this here null, might cause a nullpointer
- // in onProgressUpdate
- // textView.append(String.valueOf(values[0]));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement