如何将Enum对象添加到Android Bundle?
Bundle如果你不记得所有键的名称(甚至只能打印键名称会很酷),是否有一种简单的方法可以将a的内容打印到Logcat?
请问任何人请告诉我android中存在的所有IPC机制是什么.
据我所知:
1)意图,
2)粘合剂.
我试图在我的意图中添加一条额外的消息,以便传递给稍后触发的AlarmManager.我的onReceive正确触发,但extras.getString()返回null
建立:
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 day : weekdays) {
dayOfWeek++;
if (day == true) {
Calendar cal = Calendar.getInstance();
AlarmManager alarmManager = (AlarmManager) this
.getSystemService(Context.ALARM_SERVICE);
cal.set(Calendar.DAY_OF_WEEK, dayOfWeek);
cal.set(Calendar.HOUR_OF_DAY,
timeRule.getStartTime().get(Calendar.HOUR_OF_DAY));
cal.set(Calendar.MINUTE,
timeRule.getStartTime().get(Calendar.MINUTE));
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
cal.getTimeInMillis(), 3600000 * 7, getPendingIntent(0, "RINGER_OFF"));
} …Run Code Online (Sandbox Code Playgroud) android broadcastreceiver alarmmanager android-pendingintent android-bundle
我最近一直在使用很多Fragments并且一直在使用两种不同的方法将对象传递给Fragments,但我能看到的唯一区别是,在下面的FragmentOne采用的方法中,传入的对象必须实现Serializable界面(以及与之相关的一切).
使用一个而不是另一个有什么好处吗?
public class FragmentOne extends Fragment {
public static final String FRAGMENT_BUNDLE_KEY =
"com.example.FragmentOne.FRAGMENT_BUNDLE_KEY";
public static FragmentOne newInstance(SomeObject someObject) {
FragmentOne f = new FragmentOne();
Bundle args = new Bundle();
args.putSerializable(FRAGMENT_BUNDLE_KEY, someObject);
f.setArguments(args);
return f;
}
public SomeObject getSomeObject() {
return (SomeObject) getArguments().getSerializable(FRAGMENT_BUNDLE_KEY);
}
}
Run Code Online (Sandbox Code Playgroud)
和
public class FragmentTwo extends Fragment {
SomeObject mSomeObject;
public static FragmentTwo newInstance(SomeObject someObject) {
FragmentTwo fragment = new FragmentTwo();
fragment.setSomeObject(someObject);
return fragment;
}
public void setSomeObject(SomeObject someObject) …Run Code Online (Sandbox Code Playgroud) 我有一个Android应用程序,它维护有关行进距离,时间流逝等的状态.当用户更改屏幕时Android调用onDestroy()时,我可以方便地存储在对象中并在Bundle中存储对该对象的引用方向,然后恢复onCreate(Bundle savedBundle)中的状态.但是,我在屏幕上的Buttons和EditText对象中也有一些状态,我希望通过屏幕方向保持这种状态.例如,在onStart(Bundle savedBundle)中我调用:
_timerButton.setBackgroundColor(Color.GREEN);
_pauseButton.setBackgroundColor(Color.YELLOW);
_pauseButton.setEnabled(false);
Run Code Online (Sandbox Code Playgroud)
然后在我的应用程序的整个操作过程中,这些按钮的颜色/启用状态将被更改.是否有更方便的方法来持久保存用户界面项(EditText,Button对象等)的状态,而无需手动保存/恢复每个按钮的每个属性?在屏幕方向之间手动管理这种类型的状态感觉非常笨拙.
谢谢你的帮助.
让我们考虑一下我拥有Fragment A和的情况Fragment B.
B 声明:
public interface MyInterface {
public void onTrigger(int position);
}
Run Code Online (Sandbox Code Playgroud)
A 实现这个接口.
当Fragment B进入堆栈时,我应该如何传递Fragment A它的引用,Bundle以便在需要时A获得onTrigger回调.
我使用的情况是,A具有ListView与项目,并B具有ViewPager与项目.两者都包含相同的项目,当用户从B -> A弹出之前开始B它应该触发回调A以更新它的ListView位置以匹配B寻呼机位置.
谢谢.
我想知道是否有任何尺寸限制Parcelable附加到Intent?我了解一些文档Intents,Bundles,Parcelable再有任何关于大小限制.但我读了一些答案,说附件的大小Parcelable是有限的(例如,1 MB).因此Parcelable受尺寸限制还是仅取决于设备?
我在两个不同的活动中有两个android spinner下拉列表.但是两个微调器都有来自同一个sourec的相同数据.我想根据第一个活动的位置改变第二个Activity的位置.如何解决这个问题?
更新的代码:
第一项活动:
public class ServiceRequest extends BaseActivity implements OnItemClickListener {
private List<Item> customerList = new ArrayList<Item>();
private SpinnerAdapter adapter;
public static final String EXTRA_INTENT_CUSTOMER_LIST ="extra_intent_customer_list";
public static final String EXTRA_INTENT_SELECTED_ITEM = "extra_intent_selected_item";
private List<Item> items;
Spinner spin;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getLayoutInflater().inflate(R.layout.service_request, frameLayout);
;
);
System.out.println("Selected item " Button login = (Button) findViewById(R.id.booking);
final String message = autoCompView.getText().toString();
//Create the bundle
login.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
{
if(customerList.isEmpty()) return;
Item selectedItem = …Run Code Online (Sandbox Code Playgroud) android listadapter android-intent android-spinner android-bundle
android ×10
android-bundle ×10
alarmmanager ×1
bundle ×1
enums ×1
fragment ×1
ipc ×1
java ×1
listadapter ×1
logcat ×1
ondestroy ×1
parcelable ×1
state ×1