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 :(
interrupt()itself does nothing, only puts the flag in the interrupted state, and you must handle this state yourself. - woessscurrentThread()is a call to the current thread. InonPause()this will be the main thread, not generated by you. Callinterrupt()on your thread:thread.interrupt()- woesssthreadvariable points to it this way. And the static methodThread.currentThread()finds and returns a reference to the thread from which it was called. All system events (akaonPause) are called in the UI thread and thereforeThread.currentThread(), caused in these events will return a link to it. - woesss