How to proceed timer to run if app minimized in android?
<p>Hi I am working in chat app. I have timer and when customer gives request to expert, the timer starts to run for 1 minute and waits till it get approve. After approved/reject, timer will get cancelled. this works in normal scenario. But when app gets minimised by giving request, timer is not getting cancel even if expert approved or rejected. How to handle this situation?</p>

<p>My code is as follows:</p>

<pre><code>private static final int SECONDS_DELAY = 1000;

//when button clicked, request been sent and wait for approve..so timer s   tarts to run for a minute..
 case R.id.btn_alrt_ok:
        sendRequestToExtend();
        break;

//here i am performing logic..
private void sendRequestToExtend() {
    try {
        showRequestTimer(); //displaying timer to run..
        isFirstReq = false;
        sendChatCommand(Constants.CODE_CHAT_EXTEND + ":" + selectedOption);
        elapsed = 0;
        chatExtendTimer = new TimerTask() {
            @Override
            public void run() {
                elapsed += SECONDS_DELAY;
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        updateReqTimer(elapsed / SECONDS_DELAY,
                                Constants.SECONDS_15);
                        if (elapsed &gt;= Constants.CHAT_RESP_TIME)
                            //when app gets minimised this method is not working..
                            onChatInvitation(Constants.CHAT_EXT_REJECT,
                                    chatToPerson);
                           //in this method onChatInvitation, for request if approved in expert, i am making timer dialog to dismiss. so it's working fine if app not minimised..
                    }
                });
                return;
            }
        };
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(chatExtendTimer, SECONDS_DELAY,
                SECONDS_DELAY);
</code></pre>