{ void login(Callback callback){ ... User user = parseToUser(json); } User parseToUser(String content) { JSONObject jsonObject = new JSONObject(content); String name = jsonObject.getString("name"); return new User(name); } }
{ super.onCreate(savedInstance); // init some variables } @Override public void onDestroy() { // free some memory } public void showGalery(){} public void dismissGalery(){} public void takePhoto(){} } class ShareActivity extends BaseActivity { @Override public void onCreate(Bundle bundle) { // init some fields } public void showGalery() {} public void dismissGalery() {} }
public void showGalery() public void dismissGalery() public void takePhoto() } public class ShareHelper { public void onCreate() public void showGalery() public void dismissGalery() } class ShareAndImageActivity extends BaseActivity { ImageHelper imageHelper; ShareHelper shareHelper; @Override public void onCreate(Bundle bundle) { ... imageHelper.onCreate(); shareHelper.onCreate(); } public void onGaleryClicked() { imageHelper.showGalery(); } public void onShareClicked() { shareHelper.showGalery(); } }
} public class AuthActivity extends BaseActivity implements LoginListener { @Override public void onLogin(){} @Override public void onRegister(){} @Override public void onUsernameTextChanged() { showToastMessage(); } }
KEY_USER = "KEY_USER"; void something() { intent.putExtra(KEY_USER, user); } } public class HomeFragment extends Fragment { private static final String KEY_USER = "KEY_USER"; void something() { User user = intent.getParcelableExtra(KEY_USER); } } Create the same keys in each class
KEY_USER = "KEY_USER"; void something() { intent.putExtra(KEY_USER, user); } } public class HomeFragment extends Fragment { void something() { User user = intent.getParcelableExtra(HomeActivity.KEY_USER); } } Make the keys public
"KEY_USER"; } public class HomeActivity extends Activity { void something() { intent.putExtra(Constants.KEY_USER, user); } } public class HomeFragment extends Fragment { void something() { User user = intent.getParcelableExtra(Constants.KEY_USER); } } Put all keys to a class