Java tutorial
/* * Copyright (C) 2012 CONIT Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package jp.co.conit.sss.sn.ex2.activity; import jp.co.conit.sss.sn.ex2.R; import jp.co.conit.sss.sn.ex2.fragment.SettingsFragment; import jp.co.conit.sss.sn.ex2.service.AbstRegistObserver; import jp.co.conit.sss.sn.ex2.service.ResponseHandler; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import com.google.android.gcm.GCMRegistrar; /** * ?????Activity?? * * @author conit */ public class SettingsActivity extends FragmentActivity { private RegistObserver mRegistObserver; private class RegistObserver extends AbstRegistObserver { @Override public void onRegisted() { FragmentManager fm = getSupportFragmentManager(); SettingsFragment f = (SettingsFragment) fm.findFragmentById(R.id.frame_settings); if (f != null) { f.setRegistBtnState(); } } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); mRegistObserver = new RegistObserver(); init(getIntent()); } /** * ???? * * @param intent */ private void init(Intent intent) { FragmentManager fm = getSupportFragmentManager(); FragmentTransaction transaction = fm.beginTransaction(); SettingsFragment f = (SettingsFragment) fm.findFragmentById(R.id.frame_settings); if (f == null) { SettingsFragment fragment = SettingsFragment.newInstance(); transaction.replace(R.id.frame_settings, fragment); transaction.commit(); } } @Override protected void onStart() { super.onStart(); ResponseHandler.register(mRegistObserver); } @Override protected void onStop() { super.onStop(); ResponseHandler.unregister(mRegistObserver); } @Override public void onDestroy() { super.onDestroy(); GCMRegistrar.onDestroy(getApplicationContext()); } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); init(intent); } }