Pramod Setlur Pramod Setlur - 1 year ago 117
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download