У меня проблема с моим приложением.
Прежде всего, извините за мой плохой английский.
У меня есть MainActivity с пятью фрагментами и классом функций (FunctionsApp).
В одном из фрагментов найдено «OptionsFragment», в этом фрагменте есть кнопки для перехода в настройки, выход из системыи другие параметры.
Проблема в том, что когда внутри фрагмента (OptionsFragment) я выбираю кнопку для перехода к другой операции, после того как я вернусь (с соответствующим завершением), во фрагменте OptionsFragment я выбираю кнопкуВыйдите из системы, вызовите FunctionsApp и отобразите AlertDialog.
Отображаемая ошибка:
android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@e363980 is not valid; is your activity running?
Код:
OptionsFragment:
package com.kevin.app.activities;
import...
public class OptionsFragment extends Fragment implements NavigationView.OnNavigationItemSelectedListener {
FunctionsApp functionsapp = new FunctionsApp(getActivity());
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View vista=inflater.inflate(R.layout.fragment_options, container, false);
NavigationView navigationView = (NavigationView)vista.findViewById(R.id.nav_options_view);
navigationView.setNavigationItemSelectedListener(this);
return vista;
}
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_options_logout) {
functionsapp.logoutAsk();
} else if (id == R.id.nav_options_settings) {
functionsapp.goSettingsActivity();
}
return true;
}
}
ФункцииApp:
package com.kevin.app.aplicacion;
import..
public class FunctionsApp {
private static Context context;
public FunctionsApp(Context context) {
this.context = context;
}
// logout
public void logoutAsk() {
new AlertDialog.Builder(context)
.setMessage(R.string.message_logout_confirm)
.setCancelable(true)
.setPositiveButton(R.string.text_yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
registerLogout();
cleanAllSP();
showToast(context.getString(R.string.message_logout_yes));
goWelcomeActivity();
}
})
.setNegativeButton(R.string.text_nope, null)
.show();
}
Может мне помочь?Спасибо !!