Pramod Setlur Pramod Setlur - 4 months ago 58
Android Question

calling onOptionsItemSelected explicitly

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?


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


private void saveMe(){
    // write your save code here

now you can call this method when user navigate to another activity