簡體   English   中英

如何完成活動?

[英]How to Finish Activity?

我正在使用Recyclerview。 我想從其holder中完成當前活動。當我單擊項目時,我想打開“新活動”並完成當前活動。 請幫助我的代碼如下所示。

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);

}}

當我在holder Constructor中傳遞Activity實例時,它解決了我的問題

只需在onClick()的末尾添加下一行:

((Activity)context).finish();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM