Skip to content

Instantly share code, notes, and snippets.

@ymow
Forked from cuber5566/gist:559aee18007819b7e7f0
Last active August 29, 2015 14:21
Show Gist options
  • Save ymow/1abc069c18a82948b790 to your computer and use it in GitHub Desktop.
Save ymow/1abc069c18a82948b790 to your computer and use it in GitHub Desktop.
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