Entity:
import android.os.Parcel;
import android.os.Parcelable;
import com.biznest.campusinformation.sqlite.entity.Friend;
public class FriendET extends Friend implements Parcelable{
//below fields are used by Heartbeat
private String name;
private String replycode;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getReplycode() {
return replycode;
}
public void setReplycode(String replycode) {
this.replycode = replycode;
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
dest.writeString(name);
dest.writeString(replycode);
}
public FriendET(){
}
public FriendET(Parcel source){
this.name = source.readString();
this.replycode = source.readString();
}
public static final Parcelable.Creator<FriendET> CREATOR = new Parcelable.Creator<FriendET>(){
@Override
public FriendET createFromParcel(Parcel source) {
// TODO Auto-generated method stub
return new FriendET(source);
}
@Override
public FriendET[] newArray(int size) {
// TODO Auto-generated method stub
return new FriendET[size];
}
};
@Override
public String toString() {
return "FriendET [" + "name=" + name + ", FriendUserID=" + this.getFriendUserID()
+ ", replycode=" + replycode
+ "]";
}
}
Service:
if(fet != null){
//记录一个friendAppSize,是希望当好友申请数量改变时再发送广播,而不是每次都发送广播。
if(friendAppSize != fet.size()){
//不相等则保存申请人数大小,发广播更新UI。
friendAppSize = fet.size();
Intent intent = new Intent(Constants.ACTION_SHOW_MSGCOUNT);
intent.putExtra(Constants.MASK_FIELD, MaskType.CMD_FRIEND_APP);
intent.putExtra(Constants.MSGCOUNT_FIELD, friendAppSize);
intent.putParcelableArrayListExtra(Constants.DATA_APP_FIELD, (ArrayList<? extends Parcelable>)fet);
CoreService.this.sendBroadcast(intent);
}
}Receiver:
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
MyTrace.d(LOGTAG, MyTrace.getFileLineMethod(), "action=" + action);
if (Constants.ACTION_SHOW_MSGCOUNT.equals(action)) {
char mask = intent.getCharExtra(Constants.MASK_FIELD, '0');
int count = intent.getIntExtra(Constants.MSGCOUNT_FIELD, 0);
ArrayList<? extends Parcelable> list = intent.getParcelableArrayListExtra(Constants.DATA_APP_FIELD);
MyTrace.d(LOGTAG, MyTrace.getFileLineMethod(), "MSGCOUNT=" + count);
if(count > 0){
Message msg = mHandler.obtainMessage();
msg.arg1 = count;
msg.arg2 = mask;
msg.obj = list;
mHandler.sendMessage(msg);
}
}
}
本文介绍了一个名为FriendET的实体类,该类继承自Friend并实现了Parcelable接口,用于存储好友名称和回复码等信息。此外,还展示了如何在Android应用中通过Intent广播更新UI来显示好友申请的数量变化。
11万+

被折叠的 条评论
为什么被折叠?



