Android onResume空白屏幕
在我的Android应用程序中,除了当我点击主页按钮并等待10-15分钟并回到应用程序时,屏幕一片空白,一切都很完美。我仍然可以访问菜单项,但屏幕只是黑色。Android onResume空白屏幕
如果我的行为为正常,选择本地按钮,然后回过头来应用它是好的......它已经坐了一会儿后,其只...
任何想法?
我将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; import android.content.Intent; import android.location.Location; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.ImageButton; import android.widget.Toast; import com.myapp.R; import com.WhiteLabel.tools.Globals; import com.WhiteLabel.tools.LocationService.LocationResult; import com.WhiteLabel.tools.PreferenceHelper;
public class LoadingScreen extends Activity 保护位置currentLocation; 私有ApplicationClass应用程序; 私人ImageButton btnLocal; private ImageButton btnNational; private ImageButton btnDOD; 私人ImageButton btnDestinations; private 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;
}
}
当你的应用程序转到后台,它可能会在设备运行内存被杀死。也许这是你的问题的一部分。
您可以使用savedInstanceState来保存应用程序状态。
这可能已经工作,没有崩溃,但...仍然测试,以确保我必须等待它,所以它很烂,需要一段时间 – Jesse 2012-04-25 20:30:54
它没有工作 – Jesse 2012-04-25 21:19:19
你可以发布你的MainScreen活动的代码吗? – timoschloesser 2012-04-26 07:02:08
你能从FC发布堆栈跟踪吗? – 2012-04-25 18:51:48
嗯,可能有助于发布logcat从部队关闭?它可能会给我们一些线索。发布一些onCreate/onResume可能也有帮助。 – Gophermofur 2012-04-25 18:53:21
好吧我从logcat得到的例外,并张贴它上面 – Jesse 2012-04-25 19:18:32