这里是我的代码的一部分:“public void onDestroy()”和“protected void onDestroy()”之间的区别?
package com.admobsdk_dfp_handler;
import com.google.ads.*;
import com.google.ads.doubleclick.*;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.view.Menu;
import android.widget.RelativeLayout;
public class AdMobSDK_DFP_Handler extends Activity {
private DfpAdView adView;
private static final String adUnitId = "/7732/test_portal7/android_app1_test_portal7/top_banner_non_sdk_application_android_app1_test_portal7";
private Handler handler = new Handler();
private Runnable runnable = new Runnable() {
public void run() {
adView.loadAd(new AdRequest());
handler.postDelayed(this, 5000);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ad_mob_sdk__dfp__handler);
adView = new DfpAdView(this, AdSize.BANNER, adUnitId);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.mainLayout);
layout.addView(adView);
adView.loadAd(new AdRequest());
};
@Override
protected void onPause() {
handler.removeCallbacks(runnable);
super.onPause();
}
@Override
protected void onResume() {
handler.postDelayed(runnable, 5000);
super.onResume();
}
@Override
protected void onDestroy() {
handler.removeCallbacks(runnable);
super.onDestroy();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_ad_mob_sdk__dfp__handler,
menu);
return true;
}
}
保护无效的onDestroy()用于清理程序。但是,我看到一些示例项目,它们通常使用public void onDestroy()来进行清理。
据我所知,在Java中,保护方法可以在一个包中被访问,并公共方法可以在任何地方进行访问。但通常一个类有它自己的onDestroy(),那么这是否意味着可以使用?在他们之间进行选择时,我需要关注哪些问题?
谢谢你的帮助。
对不起,我的问题有一些错误,它是公开的而不是私人的 –
好的,我会编辑。 – Ixx
非常感谢你 –