每当我按下应用程序上的主页按钮然后再次返回时,应用程序似乎已停止。我真的不知道为什么,因为我还没有做任何事情。所以这意味着唯一被执行的是我的 oncreate、onresume、onpause 和 on destroy。我没有在 onresume、onpause 和 destroy 中做任何事情。还没有服务启动,或者只是在 oncreate 中加载和初始化数据。另一件事是,它没有崩溃,它只是停止或关闭。没有错误。我将与您分享我的 onCreate 按钮。也许您会看到导致这种情况发生的原因。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.layout_landstar_page);
preferences = getSharedPreferences(pref_data, Context.MODE_PRIVATE);
alertDialogBuilder = new AlertDialog.Builder(this);
i = new Intent(this, BGService.class);
shipmentAvailableLayout = ((LinearLayout)findViewById(R.id.shipment_available_layout));
shipmentNotAvailableLayout = ((LinearLayout)findViewById(R.id.shipment_notavailable_layout));
menu = ((RelativeLayout)findViewById(R.id.menu));
declineBtn = ((Button)findViewById(R.id.declinebtn));
acceptBtn = ((Button)findViewById(R.id.acceptbtn));
callHelpDeskBtn = ((Button)findViewById(R.id.callhelpdeskbtn));
menuBtn = ((ImageView)findViewById(R.id.menubtn));
refreshBtn = ((ImageView)findViewById(R.id.refreshbtn));
logoutBtn = ((ImageView)findViewById(R.id.logoutbtn));
trackingMsgShipment = ((TextView)findViewById(R.id.tracking_message_shipment));
powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"MyWakeLock");
registerReceiver(broadcastReceiver, new IntentFilter(BGService.BROADCAST_ACTION));
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
((Button)findViewById(R.id.acceptbtn)).setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN)
acceptBtn.setBackgroundResource(R.drawable.accept_selected);
if(event.getAction()==MotionEvent.ACTION_UP)
{
acceptBtn.setBackgroundResource(R.drawable.accept_idle);
if(isNetworkConnected())
{
acceptLoad();
}
else
noConnection();
}
return false;
}
});
((Button)findViewById(R.id.declinebtn)).setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN)
declineBtn.setBackgroundResource(R.drawable.decline_selected);
if(event.getAction()==MotionEvent.ACTION_UP)
{
declineBtn.setBackgroundResource(R.drawable.decline_idle);
declineLoad();
}
return false;
}
});
((Button)findViewById(R.id.callhelpdeskbtn)).setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN)
callHelpDeskBtn.setBackgroundResource(R.drawable.btn_refresh_selected);
if(event.getAction()==MotionEvent.ACTION_UP)
{
callHelpDeskBtn.setBackgroundResource(R.drawable.btn_refresh_idle);
if(isNetworkConnected())
{
displayProgressSpinner();
}
else
noConnection();
}
return false;
}
});
((ImageView)findViewById(R.id.menubtn)).setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN)
{
if(menu.isShown())
{
menu.setVisibility(View.GONE);
}
else
{
menu.setVisibility(View.VISIBLE);
}
}
return false;
}
});
((ImageView)findViewById(R.id.refreshbtn)).setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN)
{
menu.setVisibility(View.GONE);
if(isNetworkConnected())
displayProgressSpinner();
else
noConnection();
}
return false;
}
});
((ImageView)findViewById(R.id.logoutbtn)).setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN)
{
menu.setVisibility(View.GONE);
try{
checkerTimer.cancel();
gpsTimer.cancel();
counterTimer2.cancel();
}
catch (Exception e) {
e.printStackTrace();
}
Log.i("isAccept", preferences.getString("isAccepted",""));
alertDialogBuilder.setTitle("Message");
alertDialogBuilder
.setMessage("Clicking the log out button will stop your GPS and exit the application. Are you sure?")
.setCancelable(false)
.setNegativeButton("Logout",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
SharedPreferences.Editor editor = preferences.edit();
editor.putString("isDriverLogin", "True");
editor.putString("driverPassword", driverPassword);
editor.putString("carrierId", carrierId);
editor.putString("CCTID", cctid);
editor.putString("shipment", entityShipment);
editor.putString("isAccepted", "");
editor.commit();
getApplicationContext().stopService(i);
finish();
}
})
.setPositiveButton("Cancel",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
return false;
}
});
Intent intent = getIntent();
loadSaveDetails(intent);
}
我的清单:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
>
<activity
android:name="com.nesv.landstar.SplashScreen"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.nesv.landstar.Login"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.nesv.landstar.DriverLogin"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.nesv.landstar.LandstarPage"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<service android:name="com.nesv.landstar.BGService"></service>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
有一件事,这不会发生在有根的三星 s3 和普通的三星 s4 上。在 S duos 4.0 版和更低的姜饼上尝试过。这发生了。
另一个问题。我尝试从 Eclipse 安装它。这没有发生。仅当我尝试安装来自设备上的 bin 文件夹的 apk 文件时才会发生这种情况。