Android

동적 브로드캐스트리시버 자동 해지 auto-unregister broadcast receiver that has been registered dynamically

yo bro~


fu@ckup english!!!!!! that bitch too hard to read 

why the fucking english is all over this "Hello, World!"


besides, android api guides has not been translated completely!!!!!!!

what the fuck!

why do the fucking computer dudes get us, ching-chang-chong, hard to study it


jsaofjseoifjaoij1o2j31


동적으로 브로드캐스트 리시버를 등록하면 그것은 메모리 릭을 유발합니다.

그러므로 해당 어플리케이션 또는 작업이 더이상 유효하지 않을때 해당 브로드캐스트 리시버를 해지해주어야 합니다.





그런데 일일히 하기도 그렇고... instrumentation같은 경우에는 종료할때 발생되는 method가 없음

그러므로 알아서 timeout 하는 브로드캐스트 리시버를 만들었음.


그냥 시간가져와서 비교후에 거시기 함. 알아서 쓰도록.

public class BC extends BroadcastReceiver {
    private static final long AUTO_UNREGISTER_TIME_OUT = 10000;

    private long m_last_received;

    public BC() {
        super();
        m_last_received = new Date().getTime();
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        long time_out;
        long now;

        now = new Date().getTime(); 

        //get time out and determine whether to unregister or to update m_last_received
        time_out = now - m_last_received;
        if(time_out >= (AUTO_UNREGISTER_TIME_OUT))
        {
            //unregister
            context.unregisterReceiver(this);
        }
        else
        {
            //update m_last_received
            m_last_received = now;
        }
    }
}
,

알림

이 블로그는 구글에서 제공한 크롬에 최적화 되어있고, 네이버에서 제공한 나눔글꼴이 적용되어 있습니다.

카운터

Today :
Yesterday :
Total :

태그