2

在从一项活动切换到另一项活动时,我真的需要一些帮助来解决泄漏问题。我正在尝试使用 YouTube Android API,我将播放列表加载到一些可点击的缩略图中,然后它们可以播放视频。一切似乎都正常,但后来我注意到 Logcat 中存在泄漏。

这是我的代码:

public class MainActivity extends Activity implements
    OnInitializedListener,
    YouTubeThumbnailLoader.OnThumbnailLoadedListener, OnClickListener {

YouTubeThumbnailView thumbs1, thumbs2, thumbs3, thumbs4, thumbs5

YouTubeThumbnailLoader Loader;

ImageView play1, play2, play3, play4, play5;

RelativeLayout tempLayout;

public static final String DEVELOPER_KEY = "xxxxxxxxxxxxxxxxxxxxxxxx";

String videolist, taal;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
     requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);
    tempLayout = (RelativeLayout) findViewById(R.id.tempLayout);
    tempLayout.setVisibility(View.VISIBLE);

    taal = Locale.getDefault().getLanguage();
    if(taal.equals("nl")){
    videolist = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    }else{
    videolist = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";   
    }

    play1 = (ImageView) findViewById(R.id.play1);
    play2 = (ImageView) findViewById(R.id.play2);
    play3 = (ImageView) findViewById(R.id.play3);
    play4 = (ImageView) findViewById(R.id.play4);
    play5 = (ImageView) findViewById(R.id.play5);


    play1.setVisibility(View.INVISIBLE);
    play2.setVisibility(View.INVISIBLE);
    play3.setVisibility(View.INVISIBLE);
    play4.setVisibility(View.INVISIBLE);
    play5.setVisibility(View.INVISIBLE);

    thumbs1 = (YouTubeThumbnailView) findViewById(R.id.thumbs1);
    thumbs2 = (YouTubeThumbnailView) findViewById(R.id.thumbs2);
    thumbs3 = (YouTubeThumbnailView) findViewById(R.id.thumbs3);
    thumbs4 = (YouTubeThumbnailView) findViewById(R.id.thumbs4);
    thumbs5 = (YouTubeThumbnailView) findViewById(R.id.thumbs5);

    thumbs1.initialize(DEVELOPER_KEY, this);
    thumbs2.initialize(DEVELOPER_KEY, this);
    thumbs3.initialize(DEVELOPER_KEY, this);
    thumbs4.initialize(DEVELOPER_KEY, this);
    thumbs5.initialize(DEVELOPER_KEY, this);


}

@Override
public void onInitializationFailure(YouTubeThumbnailView v,
        YouTubeInitializationResult arg1) {
    // TODO Auto-generated method stub
    tempLayout.setVisibility(View.INVISIBLE);
    Toast.makeText( this,"Unable to initialize",Toast.LENGTH_LONG).show();


}

@Override
public void onInitializationSuccess(YouTubeThumbnailView v,
        YouTubeThumbnailLoader loader) {
    // TODO Auto-generated method stub
    this.Loader = loader;
    Loader.setOnThumbnailLoadedListener(this);
    if (v == thumbs1)
        Loader.setPlaylist(videolist, 0);
    if (v == thumbs2)
        Loader.setPlaylist(videolist, 1);
    if (v == thumbs3)
        Loader.setPlaylist(videolist, 2);
    if (v == thumbs4)
        Loader.setPlaylist(videolist, 3);
    if (v == thumbs5)
        Loader.setPlaylist(videolist, 4);

}

@Override
public void onThumbnailError(YouTubeThumbnailView v, ErrorReason arg1) {
    // TODO Auto-generated method stub
    if (isOnline() == true) {

        tempLayout.setVisibility(View.INVISIBLE);

        if (v == thumbs1)
            play1.setImageResource(R.drawable.unav);
        play1.setVisibility(View.VISIBLE);
        if (v == thumbs2)
            play2.setImageResource(R.drawable.unav);
        play2.setVisibility(View.VISIBLE);
        if (v == thumbs3)
            play3.setImageResource(R.drawable.unav);
        play3.setVisibility(View.VISIBLE);
        if (v == thumbs4)
            play4.setImageResource(R.drawable.unav);
        play4.setVisibility(View.VISIBLE);
        if (v == thumbs5)
            play5.setImageResource(R.drawable.unav);
        play5.setVisibility(View.VISIBLE);

    } else {
        tempLayout.setVisibility(View.INVISIBLE);
        Toast.makeText(this,
                "Error: "+ arg1",
                Toast.LENGTH_LONG).show();

    }
}

@Override
public void onThumbnailLoaded(YouTubeThumbnailView v, String arg1) {
    // TODO Auto-generated method stub
    tempLayout.setVisibility(View.INVISIBLE);

    play1.setVisibility(View.VISIBLE);
    play2.setVisibility(View.VISIBLE);
    play3.setVisibility(View.VISIBLE);
    play4.setVisibility(View.VISIBLE);
    play5.setVisibility(View.VISIBLE);
    v.setTag(arg1);
    v.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

    String vid = v.getTag().toString();
    if(Loader != null){
    Loader.release();
    Loader = null;
}
    Intent intent = new Intent(MainActivity.this, PlayerActivity.class);
    intent.putExtra("play", vid);
    startActivity(intent);
    finish();
}

public boolean isOnline() {
    ConnectivityManager CM = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo nwi = CM.getActiveNetworkInfo();
    if (netInfo != null && nwi.isConnected()) {
        return true;
    }
    return false;
}

} 

现在这是我通过单击缩略图完成活动时的 LogCat 输出,因此 onClick 方法中的代码:

01-30 19:29:04.122: E/ActivityThread(21292): Activity com.reemdroid.tube.MainActivity      has leaked ServiceConnection com.google.android.youtube.player.internal.r$e@42f42c50 that was originally bound here
01-30 19:29:04.122: E/ActivityThread(21292): android.app.ServiceConnectionLeaked:   Activity com.reemdroid.tube.MainActivity has leaked ServiceConnection com.google.android.youtube.player.internal.r$e@42f42c50 that was originally bound here
01-30 19:29:04.122: E/ActivityThread(21292):    at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
01-30 19:29:04.122: E/ActivityThread(21292):    at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
01-30 19:29:04.122: E/ActivityThread(21292):    at android.app.ContextImpl.bindService(ContextImpl.java:1418)
01-30 19:29:04.122: E/ActivityThread(21292):    at android.app.ContextImpl.bindService(ContextImpl.java:1407)
01-30 19:29:04.122: E/ActivityThread(21292):    at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
01-30 19:29:04.122: E/ActivityThread(21292):    at com.google.android.youtube.player.internal.r.e(Unknown Source)
01-30 19:29:04.122: E/ActivityThread(21292):    at com.google.android.youtube.player.YouTubeThumbnailView.initialize(Unknown Source)
01-30 19:29:04.122: E/ActivityThread(21292):    at com.reemdroid.tube.MainActivity.onCreate(MainActivity.java:140)
01-30 19:29:04.122: E/ActivityThread(21292):    at android.app.Activity.performCreate(Activity.java:5104)
01-30 19:29:04.122: E/ActivityThread(21292):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-30 19:29:04.122: E/ActivityThread(21292):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-30 19:29:04.122: E/ActivityThread(21292):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-30 19:29:04.122: E/ActivityThread(21292):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-30 19:29:04.122: E/ActivityThread(21292):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-30 19:29:04.122: E/ActivityThread(21292):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-30 19:29:04.122: E/ActivityThread(21292):    at android.os.Looper.loop(Looper.java:137)
01-30 19:29:04.122: E/ActivityThread(21292):    at android.app.ActivityThread.main(ActivityThread.java:5039)
01-30 19:29:04.122: E/ActivityThread(21292):    at java.lang.reflect.Method.invokeNative(Native Method)
01-30 19:29:04.122: E/ActivityThread(21292):    at java.lang.reflect.Method.invoke(Method.java:511)
01-30 19:29:04.122: E/ActivityThread(21292):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-30 19:29:04.122: E/ActivityThread(21292):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-30 19:29:04.122: E/ActivityThread(21292):    at dalvik.system.NativeStart.main(Native Method)
01-30 19:29:04.132: E/ActivityThread(21292): Activity com.reemdroid.tube.MainActivity has leaked ServiceConnection com.google.android.youtube.player.internal.r$e@42f23660 that was originally bound here
01-30 19:29:04.132: E/ActivityThread(21292): android.app.ServiceConnectionLeaked: Activity com.reemdroid.tube.MainActivity has leaked ServiceConnection com.google.android.youtube.player.internal.r$e@42f23660 that was originally bound here
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.ContextImpl.bindService(ContextImpl.java:1418)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.ContextImpl.bindService(ContextImpl.java:1407)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
01-30 19:29:04.132: E/ActivityThread(21292):    at com.google.android.youtube.player.internal.r.e(Unknown Source)
01-30 19:29:04.132: E/ActivityThread(21292):    at com.google.android.youtube.player.YouTubeThumbnailView.initialize(Unknown Source)
01-30 19:29:04.132: E/ActivityThread(21292):    at com.reemdroid.tube.MainActivity.onCreate(MainActivity.java:129)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.Activity.performCreate(Activity.java:5104)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.os.Looper.loop(Looper.java:137)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.ActivityThread.main(ActivityThread.java:5039)
01-30 19:29:04.132: E/ActivityThread(21292):    at java.lang.reflect.Method.invokeNative(Native Method)
01-30 19:29:04.132: E/ActivityThread(21292):    at java.lang.reflect.Method.invoke(Method.java:511)
01-30 19:29:04.132: E/ActivityThread(21292):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-30 19:29:04.132: E/ActivityThread(21292):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-30 19:29:04.132: E/ActivityThread(21292):    at dalvik.system.NativeStart.main(Native Method)
01-30 19:29:04.132: E/ActivityThread(21292): Activity com.reemdroid.tube.MainActivity has leaked ServiceConnection com.google.android.youtube.player.internal.r$e@42f3d140 that was originally bound here
01-30 19:29:04.132: E/ActivityThread(21292): android.app.ServiceConnectionLeaked: Activity com.reemdroid.tube.MainActivity has leaked ServiceConnection com.google.android.youtube.player.internal.r$e@42f3d140 that was originally bound here
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.ContextImpl.bindService(ContextImpl.java:1418)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.ContextImpl.bindService(ContextImpl.java:1407)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
01-30 19:29:04.132: E/ActivityThread(21292):    at com.google.android.youtube.player.internal.r.e(Unknown Source) 
01-30 19:29:04.132: E/ActivityThread(21292):    at com.google.android.youtube.player.YouTubeThumbnailView.initialize(Unknown Source)
01-30 19:29:04.132: E/ActivityThread(21292):    at com.reemdroid.tube.MainActivity.onCreate(MainActivity.java:138)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.Activity.performCreate(Activity.java:5104)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.os.Looper.loop(Looper.java:137)
01-30 19:29:04.132: E/ActivityThread(21292):    at android.app.ActivityThread.main(ActivityThread.java:5039)
01-30 19:29:04.132: E/ActivityThread(21292):    at java.lang.reflect.Method.invokeNative(Native Method)
01-30 19:29:04.132: E/ActivityThread(21292):    at   java.lang.reflect.Method.invoke(Method.java:511)
01-30 19:29:04.132: E/ActivityThread(21292):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-30 19:29:04.132: E/ActivityThread(21292):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-30 19:29:04.132: E/ActivityThread(21292):    at dalvik.system.NativeStart.main(Native Method)
01-30 19:29:04.142: E/ActivityThread(21292): Activity com.reemdroid.tube.MainActivity has leaked ServiceConnection com.google.android.youtube.player.internal.r$e@42f291f8 that was originally bound here
01-30 19:29:04.142: E/ActivityThread(21292): android.app.ServiceConnectionLeaked: Activity com.reemdroid.tube.MainActivity has leaked ServiceConnection com.google.android.youtube.player.internal.r$e@42f291f8 that was originally bound here
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.ContextImpl.bindService(ContextImpl.java:1418)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.ContextImpl.bindService(ContextImpl.java:1407)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
01-30 19:29:04.142: E/ActivityThread(21292):    at com.google.android.youtube.player.internal.r.e(Unknown Source)
01-30 19:29:04.142: E/ActivityThread(21292):    at com.google.android.youtube.player.YouTubeThumbnailView.initialize(Unknown Source)
01-30 19:29:04.142: E/ActivityThread(21292):    at com.reemdroid.tube.MainActivity.onCreate(MainActivity.java:131)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.Activity.performCreate(Activity.java:5104)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.os.Looper.loop(Looper.java:137)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.ActivityThread.main(ActivityThread.java:5039)
01-30 19:29:04.142: E/ActivityThread(21292):    at java.lang.reflect.Method.invokeNative(Native Method)
01-30 19:29:04.142: E/ActivityThread(21292):    at java.lang.reflect.Method.invoke(Method.java:511)
01-30 19:29:04.142: E/ActivityThread(21292):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-30 19:29:04.142: E/ActivityThread(21292):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-30 19:29:04.142: E/ActivityThread(21292):    at dalvik.system.NativeStart.main(Native Method)
01-30 19:29:04.142: E/ActivityThread(21292): Activity com.reemdroid.tube.MainActivity has leaked ServiceConnection com.google.android.youtube.player.internal.r$e@42f2ed08 that was originally bound here
01-30 19:29:04.142: E/ActivityThread(21292): android.app.ServiceConnectionLeaked: Activity com.reemdroid.tube.MainActivity has leaked ServiceConnection com.google.android.youtube.player.internal.r$e@42f2ed08 that was originally bound here
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.ContextImpl.bindService(ContextImpl.java:1418)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.ContextImpl.bindService(ContextImpl.java:1407)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
01-30 19:29:04.142: E/ActivityThread(21292):    at     com.google.android.youtube.player.internal.r.e(Unknown Source)
01-30 19:29:04.142: E/ActivityThread(21292):    at com.google.android.youtube.player.YouTubeThumbnailView.initialize(Unknown Source)
01-30 19:29:04.142: E/ActivityThread(21292):    at com.reemdroid.tube.MainActivity.onCreate(MainActivity.java:133)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.Activity.performCreate(Activity.java:5104)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.os.Looper.loop(Looper.java:137)
01-30 19:29:04.142: E/ActivityThread(21292):    at android.app.ActivityThread.main(ActivityThread.java:5039)
01-30 19:29:04.142: E/ActivityThread(21292):    at java.lang.reflect.Method.invokeNative(Native Method)
01-30 19:29:04.142: E/ActivityThread(21292):    at java.lang.reflect.Method.invoke(Method.java:511)
01-30 19:29:04.142: E/ActivityThread(21292):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-30 19:29:04.142: E/ActivityThread(21292):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-30 19:29:04.142: E/ActivityThread(21292):    at dalvik.system.NativeStart.main(Native Method)
01-30 19:29:04.152: E/ActivityThread(21292): Activity com.reemdroid.tube.MainActivity has leaked ServiceConnection com.google.android.youtube.player.internal.r$e@42f2bf80 that was originally bound here
01-30 19:29:04.152: E/ActivityThread(21292): android.app.ServiceConnectionLeaked: Activity com.reemdroid.tube.MainActivity has leaked ServiceConnection com.google.android.youtube.player.internal.r$e@42f2bf80 that was originally bound here
01-30 19:29:04.152: E/ActivityThread(21292):    at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
01-30 19:29:04.152: E/ActivityThread(21292):    at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
01-30 19:29:04.152: E/ActivityThread(21292):    at android.app.ContextImpl.bindService(ContextImpl.java:1418)
01-30 19:29:04.152: E/ActivityThread(21292):    at android.app.ContextImpl.bindService(ContextImpl.java:1407)
01-30 19:29:04.152: E/ActivityThread(21292):    at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
01-30 19:29:04.152: E/ActivityThread(21292):    at com.google.android.youtube.player.internal.r.e(Unknown Source)
01-30 19:29:04.152: E/ActivityThread(21292):    at   com.google.android.youtube.player.YouTubeThumbnailView.initialize(Unknown Source)
01-30 19:29:04.152: E/ActivityThread(21292):    at com.reemdroid.tube.MainActivity.onCreate(MainActivity.java:132)
01-30 19:29:04.152: E/ActivityThread(21292):    at android.app.Activity.performCreate(Activity.java:5104)
01-30 19:29:04.152: E/ActivityThread(21292):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-30 19:29:04.152: E/ActivityThread(21292):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-30 19:29:04.152: E/ActivityThread(21292):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-30 19:29:04.152: E/ActivityThread(21292):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-30 19:29:04.152: E/ActivityThread(21292):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-30 19:29:04.152: E/ActivityThread(21292):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-30 19:29:04.152: E/ActivityThread(21292):    at android.os.Looper.loop(Looper.java:137)
01-30 19:29:04.152: E/ActivityThread(21292):    at android.app.ActivityThread.main(ActivityThread.java:5039)
01-30 19:29:04.152: E/ActivityThread(21292):    at java.lang.reflect.Method.invokeNative(Native Method)
01-30 19:29:04.152: E/ActivityThread(21292):    at java.lang.reflect.Method.invoke(Method.java:511)
01-30 19:29:04.152: E/ActivityThread(21292):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-30 19:29:04.152: E/ActivityThread(21292):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-30 19:29:04.152: E/ActivityThread(21292):    at dalvik.system.NativeStart.main(Native Method)
01-30 19:29:04.152: E/ActivityThread(21292): Activity com.reemdroid.tube.MainActivity has leaked ServiceConnection com.google.android.youtube.player.internal.r$e@42f51090 that was originally bound here
01-30 19:29:04.152: E/ActivityThread(21292): android.app.ServiceConnectionLeaked: Activity com.reemdroid.tube.MainActivity has leaked ServiceConnection com.google.android.youtube.player.internal.r$e@42f51090 that was originally bound here
01-30 19:29:04.152: E/ActivityThread(21292):    at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
01-30 19:29:04.152: E/ActivityThread(21292):    at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
01-30 19:29:04.152: E/ActivityThread(21292):    at  android.app.ContextImpl.bindService(ContextImpl.java:1418)
01-30 19:29:04.152: E/ActivityThread(21292):    at android.app.ContextImpl.bindService(ContextImpl.java:1407)
01-30 19:29:04.152: E/ActivityThread(21292):    at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
01-30 19:29:04.152: E/ActivityThread(21292):    at com.google.android.youtube.player.internal.r.e(Unknown Source)
01-30 19:29:04.152: E/ActivityThread(21292):    at com.google.android.youtube.player.YouTubeThumbnailView.initialize(Unknown Source)
01-30 19:29:04.152: E/ActivityThread(21292):    at com.reemdroid.tube.MainActivity.onCreate(MainActivity.java:145)
01-30 19:29:04.152: E/ActivityThread(21292):    at android.app.Activity.performCreate(Activity.java:5104)

我错过了什么吗?我看到了一个 serviceConnection,但我认为在发布 YouTubeThumbnailLoader 时它应该消失了。

4

1 回答 1

6

每个YouTubeThumbnailView. 您只保存对其中一个的引用(在字段中this.Loader),并且您只发布了一个加载器。你想释放所有这些。

实现此目的的一种方法是保留从YouTubeThumbnailView到的地图YouTubeThumbnailLoader。在onInitializationSuccess你做map.put(view, loader)和在onClick(你释放的地方)你调用.release()所有的加载器map.valueSet()

希望有帮助!

于 2013-02-01T21:05:56.077 回答