.....(略)
Intent it= new Intent(this , MyActivity.class);
it.putExtra("myFlag", dynamicFlag);
PendingIntent pit= PendingIntent.getActivity(this, 0, it, 0);
remoteViews.setOnClickPendingIntent(R.id.btnMyButton, pit);
....(略)
上列是我在寫AppWidget時的程式片段,這段程式主要是要在App Widget上的按鈕按下時,開啟某Actitity(並傳遞myFlag extra值給該Activity)以顯示所需資訊,但當我在MyActivity取得myFlag值時卻一直都是0,百思不解,後來修改程式,將PendingIntent.getActitity的最後個參數換成:
PendingIntent pit= PendingIntent.getActivity(this, 0, it, PendingIntent.FLAG_UPDATE_CURRENT);後竟然就正常了~
關於該參數該使用那個FLAG請參考:
http://developer.android.com/reference/android/app/PendingIntent.html#getActivity(android.content.Context, int, android.content.Intent, int)
http://stackoverflow.com/questions/4472447/confusing-behavior-when-starting-new-activity-with-pendingintent/5013713#5013713
沒有留言:
張貼留言