optimize when msg.getCallback() not null

Open
#11 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
android, java
Domain
mobile-dev

Research direction

Start by locating WeakHandler's sendMessage, sendMessageAtFrontOfQueue, sendMessageAtTime, and sendMessageDelayed methods, then inspect how getCallback() messages are currently handled. Verify the callback path for immediate, front-of-queue, absolute-time, and delayed sends, and consider the issue's examples as the completion cases.

Written by the indexing model from the issue text.

Description

leak could still occur when used like bellow:
WeakHandler handler = new WeakHandler();
Message m = Message.obtain(handler.getExecHandler(), new Runnable() {
@Override
public void run() {
//do something
}
});
handler.sendMessageDelayed(m, delaytimes);

although postDelay() should be used here, but what if when we get message like this:
Message message = Message.obtain(m);
and m has a callback?

so maybe sendMessageXX() methods should be optimized:

public final boolean sendMessage(Message msg) {
    if (msg.getCallback() != null) {
        return mExec.post(msg.getCallback());
    }
    return mExec.sendMessage(msg);
}

public final boolean sendMessageAtFrontOfQueue(Message msg) {
    if (msg.getCallback() != null) {
        return postAtFrontOfQueue(msg.getCallback());
    }
    return mExec.sendMessageAtFrontOfQueue(msg);
}

public boolean sendMessageAtTime(Message msg, long uptimeMillis) {
    if (msg.getCallback() != null) {
        return postDelayed(msg.getCallback(), uptimeMillis);
    }
    return mExec.sendMessageAtTime(msg, uptimeMillis);
}

public final boolean sendMessageDelayed(Message msg, long delayMillis) {
    if (msg.getCallback() != null) {
        return postDelayed(msg.getCallback(), delayMillis);
    }
    return mExec.sendMessageDelayed(msg, delayMillis);
}
Dominant language
Java
Stars
1.5k
Forks
282
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from badoo/android-weak-handler

All issues in badoo/android-weak-handler

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.