在我的 Android 应用程序中,一切正常,除了当我点击主页按钮并等待 10-15 分钟并返回应用程序时,屏幕是空白的。我仍然可以访问菜单项,但屏幕只是黑屏。
如果我正常进行活动,请选择主页按钮,然后返回应用程序就可以了……只有在它坐了一会儿之后……
有任何想法吗?
当应用程序恢复时,我会一直发送 Toast 消息,它会一直到最后一次执行代码。所以我不知道发生了什么。
此外,当屏幕为空白时,按返回或主页会导致强制关闭
编辑:单击主页按钮时添加异常:
04-25 15:12:09.625: E/AndroidRuntime(6351): java.lang.RuntimeException: Unable to pause activity {com.MyApp/com.MyAppMain.MainScreen}: java.lang.NullPointerException
04-25 15:12:09.625: E/AndroidRuntime(6351): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2731)
04-25 15:12:09.625: E/AndroidRuntime(6351): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2678)
04-25 15:12:09.625: E/AndroidRuntime(6351): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2651)
04-25 15:12:09.625: E/AndroidRuntime(6351): at android.app.ActivityThread.access$1700(ActivityThread.java:132)
04-25 15:12:09.625: E/AndroidRuntime(6351): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1045)
04-25 15:12:09.625: E/AndroidRuntime(6351): at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 15:12:09.625: E/AndroidRuntime(6351): at android.os.Looper.loop(Looper.java:150)
04-25 15:12:09.625: E/AndroidRuntime(6351): at android.app.ActivityThread.main(ActivityThread.java:4263)
04-25 15:12:09.625: E/AndroidRuntime(6351): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 15:12:09.625: E/AndroidRuntime(6351): at java.lang.reflect.Method.invoke(Method.java:507)
04-25 15:12:09.625: E/AndroidRuntime(6351): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-25 15:12:09.625: E/AndroidRuntime(6351): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-25 15:12:09.625: E/AndroidRuntime(6351): at dalvik.system.NativeStart.main(Native Method)
04-25 15:12:09.625: E/AndroidRuntime(6351): Caused by: java.lang.NullPointerException
04-25 15:12:09.625: E/AndroidRuntime(6351): at com.MyAppMain.MainScreen.onPause(MainScreen.java:110)
04-25 15:12:09.625: E/AndroidRuntime(6351): at android.app.Activity.performPause(Activity.java:3935)
04-25 15:12:09.625: E/AndroidRuntime(6351): at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1313)
04-25 15:12:09.625: E/AndroidRuntime(6351): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2708)
04-25 15:12:09.625: E/AndroidRuntime(6351): ... 12 more
import localytics.localytics.android.LocalyticsSession;
导入android.app.Activity;导入android.content.Intent;导入android.location.Location;导入android.os.Bundle;导入 android.view.Menu;导入 android.view.MenuInflater;导入android.view.MenuItem;导入android.view.View;导入android.widget.ImageButton;导入 android.widget.Toast;导入 com.myapp.R;进口 com.WhiteLabel.tools.Globals;导入 com.WhiteLabel.tools.LocationService.LocationResult;导入 com.WhiteLabel.tools.PreferenceHelper;
公共类 LoadingScreen 扩展 Activity { 保护位置 currentLocation; 私有 ApplicationClass 应用程序;私人 ImageButton btnLocal; 私人 ImageButton btnNational;私人图像按钮 btnDOD;私人 ImageButton btnDestinations; 私人 LocalyticsSession localyticsSession;
@Override
public void onCreate(Bundle savedInstanceState)
{
try
{
//final Activity activity = this;
application = ApplicationClass.getInstance();
setTheme(application.appTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.loading_screen);
application.addressSaved = false;
InitializeControls();
// String notifytime = PreferenceHelper.GetNotificationTime(this);
InitializeLocalytics(true);
Toast.makeText(this, "Use the menu button to access your account.", Toast.LENGTH_LONG).show();
}
catch(Exception ex)
{
String s = ex.toString();
}
}
@Override
protected void onResume()
{
try
{
super.onResume();
//if(!Globals.isRelease)
//Toast.makeText(this, "Hit onresume on loading screen.", Toast.LENGTH_LONG).show();
if(this.localyticsSession!=null)
this.localyticsSession.open();
Intent extrasIntent = getIntent();
if(extrasIntent!=null)
{
Bundle extras = extrasIntent.getExtras();
if(extras!=null)
{
String message = extras.getString("load_directive");
if(message.equalsIgnoreCase("notification"))
{
getIntent().putExtra("load_directive", "");
String s = message;
GetDDClick();
}
}
}
if(!Globals.isRelease)
Toast.makeText(this, "Hit after extras intent.", Toast.LENGTH_LONG).show();
//TODO - check for null application obj
if(application.loadFailed)
{
application.loadFailed = false;
Toast.makeText(getBaseContext(), "Connection issue. Please verify you are connected to the internet!", Toast.LENGTH_LONG).show();
}
if(!Globals.isRelease)
Toast.makeText(this, "Hit end of onresume.", Toast.LENGTH_LONG).show();
}
catch(Exception ex)
{
if(!Globals.isRelease)
Toast.makeText(this, "onResume error: "+ex.toString(), Toast.LENGTH_LONG).show();
}
}
public void onPause()
{
try
{
this.localyticsSession.close();
this.localyticsSession.upload();
}
catch(Exception ex)
{
if(!Globals.isRelease)
Toast.makeText(this, "onPause error:"+ex.toString(), Toast.LENGTH_LONG).show();
}
super.onPause();
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState)
{
super.onSaveInstanceState(savedInstanceState);
// your stuff or nothing
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
// your stuff or nothing
}
private void InitializeControls()
{
btnLocal = (ImageButton)findViewById(R.id.btnLocal);
btnNational = (ImageButton)findViewById(R.id.btnNational);
btnDOD = (ImageButton)findViewById(R.id.btnDOD);
btnDestinations = (ImageButton)findViewById(R.id.btnDestinations);
btnLocal.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { GetLocalClick(); }});
btnNational.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { GetNationalClick(); }});
btnDOD.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { GetDDClick(); }});
btnDestinations.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { GetDestinationsClick(); }});
}
private void InitializeLocalytics(Boolean instantiate)
{
if(instantiate)
this.localyticsSession = new LocalyticsSession(this.getApplicationContext(),Globals.LocalyticsAppKey);
this.localyticsSession.open(); // open the session
this.localyticsSession.tagScreen("Main Menu");
this.localyticsSession.upload(); // upload any data
}
private void GetLocalClick()
{
application.loadingButtonPressed = "local";
// set application var to local
GoToDDView();
}
private void GetNationalClick()
{
application.loadingButtonPressed = "national";
application.currentDivision = "national";
// set application var to national
GoToDDView();
}
private void GetDDClick()
{
application.loadingButtonPressed = "daily";
GoToSelectedView();
}
private void GetDestinationsClick()
{
application.loadingButtonPressed = "travel";
GoToDDView();
}
private void GoToDDView()
{
Intent getResultsWindow = new Intent(LoadingScreen.this, Daily.class);
startActivity(getResultsWindow);
}
private void GoToSelectedView()
{
Intent getResultsWindow = new Intent(LoadingScreen.this, DailySelected.class);
startActivity(getResultsWindow);
}
private void GoToHomeServices()
{
Intent getResultsWindow = new Intent(LoadingScreen.this, MainMenu.class);
startActivity(getResultsWindow);
}
private void GoToMyAccount()
{
Intent configIntent = new Intent(this,MyAccount.class);
startActivity(configIntent);
}
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.loadingscreenmenu, menu);
return true;
}
public boolean onOptionsItemSelected (MenuItem item)
{
switch (item.getItemId())
{
case R.id.PROFILE:
GoToMyAccount();
return true;
case R.id.MYVOUCHERS:
Intent loadVouchersIntent = new Intent(this, Vouchers.class);
startActivity(loadVouchersIntent);
return true;
}
return false;
}
}