應用越來越空接近我有一個類定義爲實例的Java類沒有在安卓
public class ApiManager
{
private static ApiManager mInstance;
public static synchronized ApiManager getInstance()
{
return mInstance;
}
public ApiManager(Context mContext)
{
this.mContext = mContext;
mInstance = this;
}
}
我SplashActivity被定義爲
public class SplashActivity extends BaseActivity
{
private String gcmRegId;
private GoogleCloudMessaging gcm;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
notificationManager.cancelAll();
try {
if(ApiManager.getInstance() != null)
{
/* Activity already present. We need to move to main activity */
finish();
Intent i = new Intent(this, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
return;
}
}
catch (Exception e1)
{
}
我的MainActivity的onDestroy被定義爲
@Override
public void onBackPressed()
{
if(isFullScreen)
{
animateFullScreenClose();
if (mainMapFragment.postLayout.getVisibility() == View.VISIBLE)
mainMapFragment.closePinDetails();
}
else
{
MyApplication.getInstance().disconnectGoogleApi();
SocketManager.getInstance().closeConnection();
finish();
MyApplication.getInstance().stopService();
}
}
}
當我按下後退按鈕。一切都應該停止。應用程序關閉。
然而,當我再次在Android上使用主菜單啓動器圖標打開應用程序,if(ApiManager.getInstance() != null)
沒有考慮到爲空,而不是飛濺我結束了在mainActivity,
爲什麼ApiManager.getInstance()
不爲空,如果應用程序被關閉。
當你按下返回按鈕,你的應用程序進入onPause(),它不會停止。 –
因爲你從未將它設置爲null? – immibis
@immibis我的問題是,當應用程序關閉時,爲什麼它們不會爲空。 –