android-bundle

Print the contents of a Bundle to Logcat?

本小妞迷上赌 提交于 2019-11-28 21:20:35
问题 Is there an easy way to print the contents of a Bundle to Logcat if you can't remember the names of all the keys (even being able to print just the key names would be cool)? 回答1: Bundle#keySet() should work. for (String key: bundle.keySet()) { Log.d ("myApplication", key + " is a key in the bundle"); } And if you want to get the Object, you can use Bundle#get(String key)(which is also in the same documentation I linked at the top of my answer). However, keep in mind using the generic get()

Android save state on orientation change

笑着哭i 提交于 2019-11-28 16:13:56
I've got an Android application which maintains state regarding distance traveled, time elapsed, etc. This state I can conveniently store in an object and store a reference to that object in the Bundle when Android calls onDestroy() when the user changes the screen orientation, then restore the state in onCreate(Bundle savedBundle). However, I also have some state in the Buttons and EditText objects on the screen that I want to persist through screen orientations. For example, in onStart(Bundle savedBundle) I call: _timerButton.setBackgroundColor(Color.GREEN); _pauseButton.setBackgroundColor

Android: How to put an Enum in a Bundle?

跟風遠走 提交于 2019-11-28 13:53:39
问题 How do you add an Enum object to an Android Bundle? 回答1: Just pass it as int from ordinal(). Restore it from values[]. 回答2: Enums are Serializable so there is no issue. Given the following enum: enum YourEnum { TYPE1, TYPE2 } Bundle: // put bundle.putSerializable("key", YourEnum.TYPE1); // get YourEnum yourenum = (YourEnum) bundle. getSerializable("key"); Intent: // put intent.putSerializableExtra("key", yourEnum); // get yourEnum = (YourEnum) intent.getSerializableExtra("key"); 回答3: I know

Saving information from one fragment and dialog if the user navigates to another fragment

二次信任 提交于 2019-11-28 10:50:24
问题 I have a screen where the user presses a button to bring up a DialogFragment with an EditText . They enter their information, and press Ok . If they press the button again, I've made it so the EditText will display the information they had just put in, and everything works fine. However, if they enter the information, press Ok , and then use the options menu to go look at another screen/ fragment , the information will not be displayed in the EditText once they press the button again. How can

FAILED BINDER TRANSACTION while passing Bitmap from one activity to another

拜拜、爱过 提交于 2019-11-28 02:04:49
问题 I want to pass a image as a bitmap from one activity to another. And i want to know whether it is possible to do like that. Sending Activity Intent intent = new Intent(getApplicationContext(), BitmapActivity.class); Bundle b = new Bundle(); b.putParcelable("BITMAP", bitmap); intent.putExtras(b); startActivity(intent); Receiving Activity Bundle bb = this.getIntent().getExtras(); b = bb.getParcelable("BITMAP"); But i am getting !!! FAILED BINDER TRANSACTION !!! Error 回答1: You can use a global

What are the IPC mechanisms available in the Android OS?

风格不统一 提交于 2019-11-27 10:27:35
Will any one please tell me what are all the IPC mechanisms that are present in Android. To my knowledge are: Intents Binders Vladimir Ivanov IPC is inter-process communication. It describes the mechanisms used by different types of android components to communicate with one another. 1) Intents are messages which components can send and receive. It is a universal mechanism of passing data between processes. With help of the intents one can start services or activities, invoke broadcast receivers and so on. 2) Bundles are entities of data that is passed through. It is similar to the

Android cannot pass intent extras though AlarmManager

孤人 提交于 2019-11-26 20:05:49
I am trying to put an extra message in my intent to pass to AlarmManager to be triggered at a later time. My onReceive triggers correctly but extras.getString() returns null Setup: public PendingIntent getPendingIntent(int uniqueRequestCode, String extra) { Intent intent = new Intent(this, ActionReceiver.class); intent.putExtra("EXTRA", extra); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, uniqueRequestCode, intent, 0); return pendingIntent; } public void setSilentLater(TimeRule timeRule) { boolean[] weekdays = timeRule.getReoccurringWeekdays(); int dayOfWeek = 0; for (boolean

Passing objects in to Fragments

给你一囗甜甜゛ 提交于 2019-11-26 19:41:44
问题 I've been working with lots of Fragments recently and have been using two distinct methods of passing in objects to the Fragments, but the only difference that I can see is that in the approach taken by FragmentOne below, the object you pass in must implement the Serializable interface (and everything associated with that). Are there any benefits to using one over the other? public class FragmentOne extends Fragment { public static final String FRAGMENT_BUNDLE_KEY = "com.example.FragmentOne

What are the IPC mechanisms available in the Android OS?

有些话、适合烂在心里 提交于 2019-11-26 15:11:22
问题 Will any one please tell me what are all the IPC mechanisms that are present in Android. To my knowledge are: Intents Binders 回答1: IPC is inter-process communication. It describes the mechanisms used by different types of android components to communicate with one another. 1) Intents are messages which components can send and receive. It is a universal mechanism of passing data between processes. With help of the intents one can start services or activities, invoke broadcast receivers and so

Android cannot pass intent extras though AlarmManager

為{幸葍}努か 提交于 2019-11-26 07:29:05
问题 I am trying to put an extra message in my intent to pass to AlarmManager to be triggered at a later time. My onReceive triggers correctly but extras.getString() returns null Setup: public PendingIntent getPendingIntent(int uniqueRequestCode, String extra) { Intent intent = new Intent(this, ActionReceiver.class); intent.putExtra(\"EXTRA\", extra); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, uniqueRequestCode, intent, 0); return pendingIntent; } public void setSilentLater