Всякий раз, когда я нажимаю кнопку «домой» в своем приложении, вернитесь снова, приложение, похоже, остановилось. Я действительно не знаю, почему, так как я еще ничего не сделал. Таким образом, это означает, что единственное, что было выполнено, это мой oncreate, onresume, onpause и on destroy. Я ничего не делаю в onresume, onpause и уничтожить. Никакой сервис не начался или что-то просто загружать и инициализировать данные в 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);
}
Мои Manifest:
<?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 и ниже до пряников. И это произошло.
Другой вопрос. Я попытался установить его из затмения. Этого не произошло. Это происходит только тогда, когда я пытаюсь установить файл apk, который появился из папки bin на моем устройстве.
Что вы подразумеваете под ", кажется, остановились"? Есть что-нибудь в logcat? Вы делаете что-либо в любом из других методов жизненного цикла деятельности ('onResume',' onPause' и т. Д.)? –
Я назначаю булевский флаг в onResume и onPause, как это. isBackground = true и наоборот. То, что я имею в виду, остановлено, это то, что он снова начинает мое приложение. Я ожидаю, что окажусь на том же самом занятии, когда я нажму на свой домашний ключ. Но он снова начинается на моей странице всплеска. Страница до этого. И я проверил запущенные приложения в диспетчере приложений. Мое приложение имеет 0 процессов. Есть предположения? – ljpv14
Где ваш манифест? – Trikaldarshi