There are several fragments. If in some fragment to start a new thread Thread thread = new Thread(new Runnable())... then I always thread.currentThread().interrupt() in onPause() thread.currentThread().interrupt() . Further, if you try to open a fragment with a map, the application just hangs ..

Little time on the decision.

Google Fragment:

 @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.google_map_view, container, false); googleMapView = (MapView) v.findViewById(R.id.googleMap); googleMapView.onCreate(savedInstanceState); googleMapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(GoogleMap googleMap) { gMap = googleMap; } }); return v; } 

I open the fragment so

 GoogleMapViewFragment fragment = new GoogleMapViewFragment(); if (bundle!=null) fragment.setArguments(bundle); transaction.replace(R.id.frgmCont, fragment, fragmentClass); if (backStack) transaction.addToBackStack(fragmentClass); transaction.commit(); 

And if in the very fragment of the map to start Thread thread = new Thread(new Runnable())... then this fragment is not removed ie. transition to another fragment is unavailable (everything hangs when replace)

I tried to remake on AsyncTask - everything works. But this is in one place, and in order to remake this month in the whole project you have to sit :(

  • And where is your flow? interrupt() itself does nothing, only puts the flag in the interrupted state, and you must handle this state yourself. - woesss
  • the fact is that even if the thread doesn’t do anything (empty body of the stream) hangs .. For example: Opening a map fragment and initializing a new stream, then trying to open a new fragment - everything hangs .. And if you do not initialize a new stream, everything is fine - noskoffofficial
  • currentThread() is a call to the current thread. In onPause() this will be the main thread, not generated by you. Call interrupt() on your thread: thread.interrupt() - woesss
  • All the same, the same. if thread call currentThread () - will a UI thread be received? I thought that the thread that was created by new Thread () would be received. Can you direct where it is chewed? - noskoffofficial
  • one
    Why should a thread look for itself — after all, your thread variable points to it this way. And the static method Thread.currentThread() finds and returns a reference to the thread from which it was called. All system events (aka onPause ) are called in the UI thread and therefore Thread.currentThread() , caused in these events will return a link to it. - woesss

0