2016-06-09 4 views
1

Je travaille avec Recyclerview. Je veux terminer l'activité actuelle de son titulaire. Quand je clique sur l'article, je veux ouvrir Nouvelle activité et terminer l'activité en cours. pls aider mon code est montré below`Comment terminer une activité?

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

}} 
+0

appel context.finish(); –

+0

J'ai essayé de cette façon mais je n'ai pas pu appeler finish() de cette façon, –

Répondre

1

Il suffit d'ajouter la ligne suivante à la fin de la onClick():

((Activity)context).finish(); 
1

Quand je passe par exemple d'activité dans le support Constructor son résoudre mon problème