Issue
I have created a adapterview along with bottomnavigation view in my code. This is the parent activity i have used for all my naviagtion views
<activity android:name=".activity.patient.painpoint.PainPointBackView"
android:parentActivityName=".activity.patient.assessment.PatientAssessmentActivity" />
This is the adapter view which i have given as parentActivity for all the tabs
[![adapter view][1]][1]
This is one of the tab which i used,
[![tab view][2]][2]
How to navigate to the parent activity i.e, Adapter view when i clicked "assessment" icon from tab view. If i use onbackpressed() it is taking to the another tab. I dont need to call using intent since it is a adapter i need to pass all the values again. Is there any way calling Parent activity from java code(PatientAssessmentActivity.class) and if i press toolbar back button it is navigating to parent activity. i need this to happen when i click assessment tab icon.
This is the code i have used,
private void setupNavigationView() {
BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);
Menu menu = bottomNavigationView.getMenu();
MenuItem menuItem = menu.getItem(2);
menuItem.setChecked(true);
assessment = realm.where(Assessment.class).equalTo("patient_id", patientID).findFirst();
Log.v(Constants.TAG, "addsdsds " + assessment);
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.action_assessment:
**here i need to navigate to parent activity**
break;
case R.id.action_front:
Intent intent = new Intent(PainPointBackView.this, PainPointFrontView.class);
intent.putExtra("patient_id", assessment.getPatient_id());
intent.putExtra("assessment_id", assessment.getId());
startActivity(intent);
break;
case R.id.action_back:
break;
case R.id.action_left:
Intent intent2 = new Intent(PainPointBackView.this, PainPointLeftView.class);
intent2.putExtra("patient_id", assessment.getPatient_id());
intent2.putExtra("assessment_id", assessment.getId());
startActivity(intent2);
break;
case R.id.action_right:
Intent intent3 = new Intent(PainPointBackView.this, PainPointRightView.class);
intent3.putExtra("patient_id", assessment.getPatient_id());
intent3.putExtra("assessment_id", assessment.getId());
startActivity(intent3);
break;
}
return false;
}
});
}
Solution
You can try using,
Intent intent = new Intent(getApplicationContext(), PatientAssessmentActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
As per Android Doc,
FLAG_ACTIVITY_CLEAR_TOP If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent
Refer : Intent
Answered By - VishnuSP
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.