Reputation: 811
I have a Save MenuItem. This has a onOptionsItemSelected(MenuItem item)
function. It's triggered when I click on the Save menu. However, I want to call this function explicitely when the user tries to navidate to another activity without saving.
So basically how can I call this onOptionsItemSelected(MenuItem item)
from another function?
Upvotes: 0
Views: 2181
Reputation: 30855
Do one thing all the code you written in this method within for save just copy and paste in you created method for e.g.
onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case R.id.save:
saveMe();
break;
}
}
private void saveMe(){
// write your save code here
}
now you can call this method when user navigate to another activity
Upvotes: 3
Reputation: 13364
Have a function named showSaveMenu()
and inside it show the save menu if user has not saved already. Call this function from each possible exit point from the activity i.e. onBackPressed()
or from any where you start another activity and also from onOptionsItemselected()
....
Upvotes: 1