下面列出了怎么用android.os.Bundle的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void onSaveInstanceState_savesDeviceData() throws NoSuchFieldException,
IllegalAccessException {
mActivityController.setup();
setField(DropInActivity.class, mActivity, "mDeviceData", "device-data-string");
Bundle bundle = new Bundle();
mActivityController.saveInstanceState(bundle)
.pause()
.stop()
.destroy();
mActivityController = Robolectric.buildActivity(DropInUnitTestActivity.class);
mActivity = (DropInUnitTestActivity) mActivityController.get();
mActivityController.setup(bundle);
assertEquals("device-data-string", getField(DropInActivity.class, mActivity, "mDeviceData"));
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
currentAudioCallback = new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable observable, int i) {
onCurrentAudioChanged(currentAudio.get());
}
};
currentAlbumArtCallback = new Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(Observable observable, int i) {
getActivity().runOnUiThread(() -> {
onCurrentAlbumArtChanged(currentAlbumArt.get());
});
}
};
}
/**
* Creates a splash screen
* @param savedInstanceState
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
thisActivity = this;
downloadProgressText = (TextView) findViewById(R.id.download_progress_text);
currentTask = (TextView) findViewById(R.id.progress_current_task);
downloadProgressBar = (ProgressBar) findViewById(R.id.download_progress_bar);
if (savedInstanceState == null) {
try {
blockChain = BlockChain.getInstance(getApplicationContext());
handler = new Handler();
initTextHandler = new Handler();
initTextHandler.post(initTextUpdater);
handler.post(startBlockChain);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* Send timing information.
*
* @param category The event category.
* @param variable The variable.
* @param label The label.
* @param duration The duration.
*/
public static void sendTiming(final Category category, final String variable, final String label, final long duration) {
getDefaultFirebaseAnalytics();
Bundle params = new Bundle();
params.putString("category", category.toString());
params.putString("variable", variable);
if (label == null) {
params.putString("label", variable);
}
else {
params.putString("label", variable + " - " + label);
}
params.putLong("value", duration);
mFirebaseAnalytics.logEvent("Timing", params);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_catalogue, container, false);
catalogueListView = (ListView)view.findViewById(R.id.catalogue);
catalogueListView.setOnItemClickListener(this);
Bundle bundle = getArguments();
if (bundle != null) {
mArgument = bundle.getString(ARGUMENT);
}
bookCatalogueList = new ArrayList<>();
bookCatalogueList = DataSupport.where("bookpath = ?", mArgument).find(BookCatalogue.class);
CatalogueAdapter catalogueAdapter = new CatalogueAdapter(getActivity(),bookCatalogueList);
catalogueListView.setAdapter(catalogueAdapter);
return view;
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_area_picker, container, false);
root.findViewById(R.id.iv_cancel).setOnClickListener(v -> {
hideDialog();
});
root.findViewById(R.id.tv_finish).setOnClickListener(v -> {
int[] items = wheelOptions.getCurrentItems();
String text = areaUtils.getOptions1Items().get(items[0]) + "-"
+ areaUtils.getOptions2Items().get(items[0]).get(items[1]) + "-"
+ areaUtils.getOptions3Items().get(items[0]).get(items[1]).get(items[2]);
Bundle data = new Bundle();
data.putString(KEY_SELECTED_AREA, text);
setResult(Activity.RESULT_OK, data);
hideDialog();
});
wheelOptions = new WheelOptions<>(root, true);
return root;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ViewUtils.inject(this);
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
String[] tabs = getResources().getStringArray(R.array.super_setting);
String uid = AppSPUtils.getUid(this);
Fragment[] fragments = {new SuperSettingCommonFragment(), new SuperSettingUserFragment()};
viewPager.setAdapter(new SimplePagerAdapter(getSupportFragmentManager(), tabs, fragments));
SlidingTabLayout indicator = (SlidingTabLayout) findViewById(R.id.slidingIndicator);
indicator.setDividerColors(0);
indicator.setSelectedIndicatorColors(ThemeUtils.getThemeColor(this));
indicator.setViewPager(viewPager);
setCurr(indicator);
}
@Override
public void init(Bundle savedInstanceState) {
drawer = this;
// add head Item (menu will be loaded automatically)
this.addHeadItem(getHeadItem1());
this.addHeadItem(getHeadItem2());
this.addHeadItem(getHeadItem3());
this.addHeadItem(getHeadItem4());
this.addHeadItem(getHeadItem5());
// load menu
this.loadMenu(getCurrentHeadItem().getMenu());
// load the MaterialItemSectionFragment, from the given startIndex
this.loadStartFragmentFromMenu(getCurrentHeadItem().getMenu());
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_real);
if (savedInstanceState == null) {
DevicePolicyManager manager = (DevicePolicyManager)
getSystemService(Context.DEVICE_POLICY_SERVICE);
if (manager.isProfileOwnerApp(getApplicationContext().getPackageName())) {
// If the managed profile is already set up, we show the main screen.
showMainFragment();
} else {
// If not, we show the set up screen.
showSetupProfile();
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean isSpeechEnabled = SpeechRecognizer.isRecognitionAvailable(this);
// Determine fragment to use
Fragment searchFragment = isSpeechEnabled
? new LeanbackSearchFragment()
: new TextSearchFragment();
// Add fragment
getSupportFragmentManager()
.beginTransaction()
.replace(android.R.id.content, searchFragment)
.commit();
}
public Builder extend(Builder builder) {
Bundle wearableBundle = new Bundle();
if (this.mFlags != 1) {
wearableBundle.putInt(KEY_FLAGS, this.mFlags);
}
if (this.mInProgressLabel != null) {
wearableBundle.putCharSequence(KEY_IN_PROGRESS_LABEL, this.mInProgressLabel);
}
if (this.mConfirmLabel != null) {
wearableBundle.putCharSequence(KEY_CONFIRM_LABEL, this.mConfirmLabel);
}
if (this.mCancelLabel != null) {
wearableBundle.putCharSequence(KEY_CANCEL_LABEL, this.mCancelLabel);
}
builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle);
return builder;
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);
mLoadingAnimView = (LoadingAnimView) findViewById(R.id.loading_anim_view);
mLoadingAnimView.setOnViewAnimEndListener(new LoadingAnimView.OnViewAnimEndListener() {
@Override
public void onViewAnimEnd() {
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
SplashActivity.this.startActivity(intent);
SplashActivity.this.finish();
}
});
//mLoadingAnimView.startAnim();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_main, container, false);
View view = binding.getRoot();
initializeAll();
return view;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final View view = View.inflate(this, R.layout.welcome_actvivity, null);
setContentView(view);
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.welcome_frame);
BaseApplication application = (BaseApplication) getApplication();
if (application.isTablet()) {
frameLayout
.setBackgroundResource(R.drawable.wecome_tablet_background);
} else {
frameLayout.setBackgroundResource(R.drawable.wecome_background);
}
// 渐变启动 从x透明度到x透明度渐变启动
AlphaAnimation alphaAnimation = new AlphaAnimation(0.1f, 1.0f);
// 持续时间
alphaAnimation.setDuration(2000);
alphaAnimation.setAnimationListener(new MyAnimationListener());
view.setAnimation(alphaAnimation);
}
private void onOpenFileResult(int resultCode, Intent data) {
if (resultCode != RESULT_OK) return;
Bundle extras = data.getExtras();
if (extras == null) return;
String fileName = extras.getString(OpenActivity.FILE_NAME_KEY);
String fileText = extras.getString(OpenActivity.FILE_TEXT_KEY);
if (TextUtils.isEmpty(fileName) || fileText == null) return;
MongolEditText editText = inputWindow.getEditText();
editText.setText(fileText);
editText.setSelection(0);
inputWindow.recordSavedContent();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
FloatingActionButton floatingButton = mFragmentHolder.enableActionButton();
floatingButton.setImageDrawable(getContext().getDrawable(R.drawable.ic_send));
floatingButton.setOnClickListener(v -> {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
File file = MapTrek.getApplication().getExceptionLog();
intent.putExtra(Intent.EXTRA_STREAM, ExportProvider.getUriForFile(getContext(), file));
intent.setType("vnd.android.cursor.dir/email");
intent.putExtra(Intent.EXTRA_SUBJECT, "MapTrek crash report");
StringBuilder text = new StringBuilder();
text.append("Device : ").append(Build.DEVICE);
text.append("\nBrand : ").append(Build.BRAND);
text.append("\nModel : ").append(Build.MODEL);
text.append("\nProduct : ").append(Build.PRODUCT);
text.append("\nLocale : ").append(Locale.getDefault().toString());
text.append("\nBuild : ").append(Build.DISPLAY);
text.append("\nVersion : ").append(Build.VERSION.RELEASE);
try {
PackageInfo info = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
if (info != null) {
text.append("\nApk Version : ").append(info.versionCode).append(" ").append(info.versionName);
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
intent.putExtra(Intent.EXTRA_TEXT, text.toString());
startActivity(Intent.createChooser(intent, getString(R.string.send_crash_report)));
mFragmentHolder.disableActionButton();
mFragmentHolder.popCurrent();
});
}
public static DefaultRefreshViewFragment newInstance(int mode, String title) {
DefaultRefreshViewFragment fragment = new DefaultRefreshViewFragment();
Bundle args = new Bundle();
args.putInt(MODE, mode);
args.putString(TITLE, title);
fragment.setArguments(args);
return fragment;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final Activity activity = getActivity();
if (activity instanceof ContentHost) {
host = (ContentHost) activity;
host.setTitle(title);
}
final View root = getView();
if (root == null) {
throw new IllegalStateException();
}
vgMutex = (MutexViewGroup) root.findViewById(R.id.vg_mutex);
final View content = root.findViewById(R.id.vg_content);
vBeforeEvent = content.findViewById(R.id.v_before_event);
vBeforeEvent.setVisibility(View.GONE);
vAfterEvent = content.findViewById(R.id.v_after_event);
vAfterEvent.setVisibility(View.GONE);
cardHappeningNow = (CardView) content.findViewById(R.id.card_happening_now);
cardHappeningNow.setVisibility(View.GONE);
cardHappeningNow.setOnClickListener(new HappeningNowOnClickListener());
cardUpNext = (CardView) content.findViewById(R.id.card_up_next);
cardUpNext.setVisibility(View.GONE);
cardUpNext.setOnClickListener(new UpNextOnClickListener());
tvDescription = (TextView) content.findViewById(R.id.tv_description);
updateUi();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
displayRotation = getWindowManager().getDefaultDisplay().getRotation();
String enableCrashHandler = RLSysUtil.getApplicationMetaData(this, "ENABLE_CRASH_HANDLER");
if (enableCrashHandler != null && enableCrashHandler.equals("false")) {
isEnableCrashHandler = false;
}
String enableAnalytics = RLSysUtil.getApplicationMetaData(this, "ENABLE_ANALYTICS");
if (enableAnalytics != null && enableAnalytics.equals("true")) {
isEnableAnalytics = true;
}
String enableFeedback = RLSysUtil.getApplicationMetaData(this, "ENABLE_FEEDBACK");
if (enableFeedback != null && enableFeedback.equals("true")) {
isEnableFeedback = true;
}
if (isEnableCrashHandler) {
RLCrashHandler.getInstance().init(this);
}
if (isEnableAnalytics) {
RLAnalyticsHelper.init(this, BuildConfig.DEBUG);
}
if (isEnableFeedback) {
RLFeedbackHelper.init(this, BuildConfig.DEBUG);
}
if (getApplication() instanceof RLApplication) {
((RLApplication) getApplication()).setDisplayInfo(RLSysUtil.getDisplayInfo(this));
}
}
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
rowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
setSearchResultProvider(this);
setOnItemClickedListener(getDefaultItemClickedListener());
delayedLoad = new SearchRunnable();
}
@Override
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.prefs_screen_preferences);
final Resources res = getResources();
final Context context = getActivity();
// When we are called from the Settings application but we are not already running, some
// singleton and utility classes may not have been initialized. We have to call
// initialization method of these classes here. See {@link LatinIME#onCreate()}.
RichInputMethodManager.init(context);
final boolean showVoiceKeyOption = res.getBoolean(
R.bool.config_enable_show_voice_key_option);
if (!showVoiceKeyOption) {
removePreference(Settings.PREF_VOICE_INPUT_KEY);
}
if (!AudioAndHapticFeedbackManager.getInstance().hasVibrator()) {
removePreference(Settings.PREF_VIBRATE_ON);
}
if (!Settings.readFromBuildConfigIfToShowKeyPreviewPopupOption(res)) {
removePreference(Settings.PREF_POPUP_ON);
}
refreshEnablingsOfKeypressSoundAndVibrationSettings();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
setButton(BUTTON_NEGATIVE, getContext().getString(android.R.string.cancel), this);
setButton(BUTTON_POSITIVE, getContext().getString(android.R.string.ok), this);
setView(mPicker);
//Install contents
super.onCreate(savedInstanceState);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
view = new FastImageProcessingView(this);
pipeline = new FastImageProcessingPipeline();
video = new VideoResourceInput(view, this, R.raw.image_processing_birds);
edgeDetect = new SobelEdgeDetectionFilter();
image = new JPGFileEndpoint(this, false, Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pictures/outputImage", false);
screen = new ScreenEndpoint(pipeline);
video.addTarget(edgeDetect);
edgeDetect.addTarget(image);
edgeDetect.addTarget(screen);
pipeline.addRootRenderer(video);
view.setPipeline(pipeline);
setContentView(view);
pipeline.startRendering();
video.startWhenReady();
view.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent me) {
if (System.currentTimeMillis() - 100 > touchTime) {
touchTime = System.currentTimeMillis();
if (video.isPlaying()) {
video.stop();
} else {
video.startWhenReady();
}
}
return true;
}
});
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.large_toolbar_fix).setOnClickListener(this);
findViewById(R.id.scroll_toolbar).setOnClickListener(this);
findViewById(R.id.collapse_large_toolbar).setOnClickListener(this);
findViewById(R.id.scroll_collapse_large_toolbar).setOnClickListener(this);
findViewById(R.id.parallax_image_toolbar).setOnClickListener(this);
findViewById(R.id.custom_behavior).setOnClickListener(this);
findViewById(R.id.snackbar).setOnClickListener(this);
findViewById(R.id.pager_tabs).setOnClickListener(this);
findViewById(R.id.pager_tabs_fixed_image).setOnClickListener(this);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_interface);
SettingsActivity.bindPreferenceSummaryToValue(findPreference("prayer_highlight"));
SettingsActivity.bindPreferenceSummaryToValue(findPreference("ui_theme"));
Preference showAmPm = findPreference("show_ampm");
Preference widgetBackground = findPreference("widget_background_color");
Preference widgetImsak = findPreference("widget_show_imsak");
Preference widgetSyuruk = findPreference("widget_show_syuruk");
Preference widgetDhuha = findPreference("widget_show_dhuha");
Preference widgetMasihi = findPreference("widget_show_masihi");
Preference widgetHijri = findPreference("widget_show_hijri");
Preference.OnPreferenceChangeListener widgetChange = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
WidgetService.start(getActivity());
return true;
}
};
showAmPm.setEnabled(!DateFormat.is24HourFormat(getActivity()));
widgetBackground.setOnPreferenceChangeListener(widgetChange);
widgetImsak.setOnPreferenceChangeListener(widgetChange);
widgetSyuruk.setOnPreferenceChangeListener(widgetChange);
widgetDhuha.setOnPreferenceChangeListener(widgetChange);
widgetMasihi.setOnPreferenceChangeListener(widgetChange);
widgetHijri.setOnPreferenceChangeListener(widgetChange);
Dagger.getGraph(getActivity())
.getAnalyticsProvider()
.trackViewedScreen(AnalyticsProvider.SCREEN_SETTINGS_INTERFACE);
}
@Override
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) {
final Intent intent = new Intent(context, IndieAuthActivity.class);
intent.putExtra("com.indieweb.indigenous.AccountType", accountType);
intent.putExtra(IndieAuthActivity.TOKEN_TYPE, authTokenType);
final Bundle bundle = new Bundle();
bundle.putParcelable(AccountManager.KEY_INTENT, intent);
return bundle;
}
@Override
@Nullable
public Bundle onSaveState() {
Bundle b = new Bundle();
int[] backStack = new int[mBackStack.size()];
int index = 0;
for (Integer id : mBackStack) {
backStack[index++] = id;
}
b.putIntArray(KEY_BACK_STACK_IDS, backStack);
return b;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_conversion_listview);
currences_names = new ArrayList<>();
mListview = findViewById(R.id.listView);
mCurrencySearch = findViewById(R.id.currencySearch);
mContext = this;
addCurrencies();
mCurrencySearch.addTextChangedListener(this);
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_code_rules);
ButterKnife.bind(this);
// set up toolbar
setupToolbar();
handleIntent(getIntent());
}
@Override
public void onLoadFinished(Loader<AsyncTaskLoaderResult<T>> loader, AsyncTaskLoaderResult<T> result) {
T data = result != null ? result.data : null;
WeiboException exception = result != null ? result.exception : null;
Bundle args = result != null ? result.args : null;
switch (loader.getId()) {
case NEW_MSG_LOADER_ID:
mTimeLineSwipeRefreshLayout.setRefreshing(false);
if (Utility.isAllNotNull(exception)) {
if (isDebug || !exception.getError().trim().equals("用户请求超过上限")) {
newMsgTipBar.setError(exception.getError());
}
onNewMsgLoaderFailedCallback(exception);
} else {
onNewMsgLoaderSuccessCallback(data, args);
}
break;
case OLD_MSG_LOADER_ID:
if (exception != null) {
showErrorFooterView();
onOldMsgLoaderFailedCallback(exception);
} else if (data != null) {
mCanLoadOldData = data.getSize() > 1;
onOldMsgLoaderSuccessCallback(data);
getAdapter().notifyDataSetChanged();
dismissFooterView();
} else {
mCanLoadOldData = false;
dismissFooterView();
}
break;
}
getLoaderManager().destroyLoader(loader.getId());
}