Android 如何完成活动?
我和Recyclerview一起工作。我想从其持有者处完成当前活动。当我单击项目时,我想打开新活动并完成当前活动。请帮忙 我的代码如下所示`Android 如何完成活动?,android,Android,我和Recyclerview一起工作。我想从其持有者处完成当前活动。当我单击项目时,我想打开新活动并完成当前活动。请帮忙 我的代码如下所示` public class GcmNotificationHolder extends RecyclerView.ViewHolder implements View.OnClickListener { protected TextView gcmMessage; protected TextView messageTital;
public class GcmNotificationHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
protected TextView gcmMessage;
protected TextView messageTital;
protected TextView messageDate;
protected ImageButton removeMessage;
protected Context context;
protected List<Notification> notificationList;
protected boolean isRead = true;
public GcmNotificationHolder(View itemView, List<Notification> notificationList, Context applicationContext) {
super(itemView);
itemView.setOnClickListener(this);
context = applicationContext;
this.gcmMessage = (TextView)itemView.findViewById(R.id.gcmMessage);
this.messageTital=(TextView)itemView.findViewById(R.id.messagTital);
this.messageDate=(TextView)itemView.findViewById(R.id.gcmMessageDate);
this.notificationList = notificationList;
}
@Override
public void onClick(View v) {
Intent intent = new Intent(context.getApplicationContext(), NotificationDescriptionActivity.class);
intent.putExtra("messageDescription", notificationList.get(getAdapterPosition()).getMessage());
intent.putExtra("messageTital", notificationList.get(getAdapterPosition()).getMessagetital());
intent.putExtra("messageDate", notificationList.get(getAdapterPosition()).getMessagedate());
notificationList.get(getAdapterPosition()).getId();
notificationList.get(getAdapterPosition()).setIsRead(true);
DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, "notification-db", null);
SQLiteDatabase db = helper.getWritableDatabase();
DaoMaster daoMaster = new DaoMaster(db);
DaoSession daoSession = daoMaster.newSession();
NotificationDao notificationDao = daoSession.getNotificationDao();
notificationDao.updateInTx(notificationList);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}}
公共类GcmNotificationHolder扩展了RecyclerView.ViewHolder实现了View.OnClickListener{
受保护的文本视图GCM消息;
受保护的文本视图消息标题;
受保护的文本视图消息日期;
受保护的ImageButtonRemoveMessage;
受保护的语境;
受保护列表通知列表;
受保护布尔值isRead=true;
公共GcmNotificationHolder(查看项目视图、列表通知列表、上下文应用程序上下文){
超级(项目视图);
setOnClickListener(这个);
上下文=应用上下文;
this.gcmMessage=(TextView)itemView.findViewById(R.id.gcmMessage);
this.messageTital=(TextView)itemView.findViewById(R.id.messagTital);
this.messageDate=(TextView)itemView.findViewById(R.id.gcmMessageDate);
this.notificationList=notificationList;
}
@凌驾
公共void onClick(视图v){
Intent Intent=新意图(context.getApplicationContext(),NotificationDescriptionActivity.class);
intent.putExtra(“messageDescription”,notificationList.get(getAdapterPosition()).getMessage());
intent.putExtra(“messageTital”,notificationList.get(getAdapterPosition()).getMessagetital());
intent.putExtra(“messageDate”,notificationList.get(getAdapterPosition()).getMessagedate());
notificationList.get(getAdapterPosition()).getId();
notificationList.get(getAdapterPosition()).setIsRead(true);
DaoMaster.DevOpenHelper helper=新的DaoMaster.DevOpenHelper(上下文,“通知数据库”,null);
SQLiteDatabase db=helper.getWritableDatabase();
道士道士=新道士(db);
DaoSession DaoSession=daoMaster.newSession();
NotificationDao NotificationDao=daoSession.getNotificationDao();
notificationDao.updateInTx(notificationList);
intent.addFlags(intent.FLAG\u活动\u新任务);
背景。开始触觉(意图);
}}
当我在holder构造函数中传递Activity实例时,请解决我的问题只需在onClick()的末尾添加下一行即可:
调用context.finish();我尝试了这种方式,但无法以这种方式调用finish(),
((Activity)context).finish();