我注意到在不同的API上有趣的活动行为:
所以问题是新的Android API有什么变化?活动生命周期有哪些变化?
在系统需要更多内存的情况下,它可能会终止暂停的进程以回收资源。
这可能是一个解释,但为什么在不同的API中执行我的代码时系统的行为会有所不同?
是否可以告诉系统我仍然需要我的活动?
我必须说我的申请执行繁重的职责。这是我的代码的一部分:
ACTIVITY CLASS
\App\User
明确声明
public class OverlayActivity extends Activity {
private static boolean isRunning = false;
private AdManager mManager;
public static void runActivity(Context context){
if (isRunning)
return;
Intent intent = new Intent(context, OverlayActivity.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
context.startActivity(intent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
getWindow().setLayout(-1, -1);
super.onCreate(savedInstanceState);
isRunning = true;
Log.d("TAG", "OverlayActivity onCreate");
mManager = new AdManager(this,"http://my.mobfox.com/request.php",
"267d72ac3f77a3f447b32cf7ebf20673", true);
mManager.setListener(new AdListener() {
@Override
public void adClicked() {
Log.d("TAG", "AdListener adClicked");
}
@Override
public void adClosed(Ad ad, boolean b) {
Log.d("TAG", "AdListener adClosed");
OverlayActivity.this.finish();
}
@Override
public void adLoadSucceeded(Ad ad) {
if (mManager != null && mManager.isAdLoaded())
mManager.showAd();
}
@Override
public void adShown(Ad ad, boolean b) {
Log.d("TAG", "AdListener adShown");
}
@Override
public void noAdFound() {
Log.d("TAG", "AdListener noAdFound");
OverlayActivity.this.finish();
}
});
mManager.requestAd();
}
@Override
protected void onStart() {
super.onStart();
Log.d("TAG", "OverlayActivity onStart");
}
@Override
protected void onResume() {
super.onResume();
Log.d("TAG", "OverlayActivity onResume");
}
@Override
protected void onPause() {
super.onPause();
Log.d("TAG", "OverlayActivity onPause");
}
@Override
protected void onStop() {
super.onStop();
Log.d("TAG", "OverlayActivity onStop");
}
@Override
protected void onDestroy() {
Log.d("TAG", "OverlayActivity onDestroy");
isRunning = false;
super.onDestroy();
if (mManager!=null)
mManager.release();
mManager=null;
}
}
ACTIVITY LAUNCH POINT
<activity android:name=".OverlayActivity"
android:excludeFromRecents="true"
android:noHistory="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:finishOnTaskLaunch="true"/>
请给我一些有关可能导致此类不同活动行为的新Android API更改的信息。
任何帮助将不胜感激。