-
-
Save ymow/1abc069c18a82948b790 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MusicFragment extends Fragment implements Handler.Callback { | |
/** | |
* New Instance | |
*/ | |
public static MusicFragment newInstance() { | |
fragment = new MusicFragment(); | |
Bundle args = new Bundle(); | |
fragment.setArguments(args); | |
return fragment; | |
} | |
/** | |
* Life Cycle | |
*/ | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setHasOptionsMenu(true); | |
setupHandlers(); | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
View rootView = inflater.inflate(R.layout.fragment_music, container, false); | |
return rootView; | |
} | |
/** | |
* Destory Handler | |
*/ | |
@Override | |
public void onDestroy() { | |
backgroundHandler.removeCallbacksAndMessages(null); | |
uiHandler.removeCallbacksAndMessages(null); | |
backgroundHandler.getLooper().quit(); | |
super.onDestroy(); | |
} | |
/** | |
* Setup Handler | |
*/ | |
private void setupHandlers() { | |
HandlerThread handlerThread = new HandlerThread("MusicFragment.background"); | |
handlerThread.start(); | |
backgroundHandler = new Handler(handlerThread.getLooper(), this); | |
uiHandler = new Handler(getActivity().getMainLooper(), this); | |
} | |
/** | |
* Handle Message | |
*/ | |
@Override | |
public boolean handleMessage(Message msg) { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment