Когда я перехожу от фрагмента входа в MainActivity Directly к Home Activity, внутри logcat возникает эта ошибка:
1742-2998 WindowManager system_server E win= Окно {b2e7c3a u0 com.example.synthshine_music/com.example.synthshine_music.MainActivity} DestroySurfaces: appStopped=true cleanupOnResume=false win.mWindowRemovalAllowed=false win.mRemoveOnExit=false win.mViewVisibility=8 caller=com.android.server.wm .ActivityRecord.destroySurfaces: 6862 com.android.server.wm.ActivityRecord.destroySurfaces: 6843 com.android.server.wm.ActivityRecord.activityStopped: 7510 com.android.server.wm.ActivityClientController.activityStopped: 310 android.app.IActivityClientController $Stub.onTransact:702 com.android.server.wm.ActivityClientController.onTransact:175 android.os.Binder.execTransactInternal:1380
Я предполагаю это связано с тем, как я управляю фрагментами, но понятия не имею,
Я новичок в разработке для Android и использовал GPT для значительной части своего проекта. Мой учитель не учил нас, как обращаться с фрагментами, и я предполагаю, что эта проблема возникает из-за этого. Мое приложение ни разу не вышло из строя, однако мне бы хотелось, чтобы эта ошибка была устранена.
Функция интересов, вероятно,
OnBackPressed в MainActivity
и StartActivityWithDelay во фрагменте входа в систему .
Вот мой код MainActivity:
package com.example.synthshine_music;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
public class MainActivity extends AppCompatActivity {
TextView tvAppName, tvNewUser;
ImageView ivIllustration;
Button btnLogIn;
FrameLayout flContainer;
int count = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
FragmentManager fragmentManager = getSupportFragmentManager();
if (fragmentManager.getBackStackEntryCount() > 0) {
fragmentManager.popBackStack();
enableMainViews(); // Enable main views when fragment is popped
tvNewUser.setEnabled(true);
} else {
finish(); // or super.onBackPressed();
}
}
});
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
tvAppName = findViewById(R.id.tvAppName);
tvNewUser = findViewById(R.id.tvNewUser);
ivIllustration = findViewById(R.id.ivIllustration);
btnLogIn = findViewById(R.id.btnLogIn);
flContainer = findViewById(R.id.flContainer);
tvAppName.setOnClickListener(v -> {
if (count == 5) {
Toast.makeText(MainActivity.this, "AMOLED Activated!", Toast.LENGTH_SHORT).show();
count = 0;
}
count++;
});
tvNewUser.setOnClickListener(v -> {
disableMainViews(); // Disable main views when fragment is shown
tvNewUser.setEnabled(false);
replaceFragment(new Register());
});
btnLogIn.setOnClickListener(v -> {
disableMainViews(); // Disable main views when fragment is shown
tvNewUser.setEnabled(false);
replaceFragment(new Login());
});
updateIllustration(getResources().getConfiguration());
}
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
updateIllustration(newConfig);
}
private void updateIllustration(Configuration config) {
if ((config.uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES) {
ivIllustration.setImageResource(R.drawable.illustration_dark);
} else {
ivIllustration.setImageResource(R.drawable.illustration);
}
}
// Method to enable or disable touch for main views
private void disableMainViews() {
tvAppName.setEnabled(false);
ivIllustration.setEnabled(false);
btnLogIn.setEnabled(false);
}
// Method to enable or disable touch for main views
void enableMainViews() {
tvAppName.setEnabled(true);
ivIllustration.setEnabled(true);
btnLogIn.setEnabled(true);
}
private void replaceFragment(Fragment fragment) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction().setCustomAnimations(R.anim.slide_lr, R.anim.slide_lr, R.anim.slide_rl, R.anim.slide_rl);
fragmentTransaction.replace(R.id.flContainer, fragment).addToBackStack(null);
fragmentTransaction.commit();
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
return super.dispatchTouchEvent(ev);
}
}
Фрагмент входа:
package com.example.synthshine_music;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.blogspot.atifsoftwares.animatoolib.Animatoo;
import com.google.android.material.textfield.TextInputEditText;
import java.util.Objects;
import java.util.regex.Pattern;
public class Login extends Fragment {
private static final String EMAIL_REGEX_PATTERN = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
private static final Pattern EMAIL_PATTERN = Pattern.compile(EMAIL_REGEX_PATTERN);
private TextInputEditText etEmail, etPassword;
private ImageView ivIllustrationLogin;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_login, container, false);
etEmail = view.findViewById(R.id.etEmail);
etPassword = view.findViewById(R.id.etPassword);
Button btnLogin = view.findViewById(R.id.btnLogInlogin);
ivIllustrationLogin = view.findViewById(R.id.ivIllustrationLogin);
btnLogin.setOnClickListener(v -> {
String email = Objects.requireNonNull(etEmail.getText()).toString();
String password = Objects.requireNonNull(etPassword.getText()).toString();
if (email.isEmpty()) {
showErrorWithAnimation(etEmail, "Email cannot be empty");
} else if (!isValidEmail(email)) {
showErrorWithAnimation(etEmail, "Invalid email");
} else if (password.isEmpty()) {
showErrorWithAnimation(etPassword, "Password cannot be empty");
} else if (password.length() < 8) {
showErrorWithAnimation(etPassword, "Password must be at least 8 characters long");
} else {
startHomeActivityWithDelay();
}
});
updateIllustration(getResources().getConfiguration());
return view;
}
private void showErrorWithAnimation(EditText editText, String errorMessage) {
Animation shake = AnimationUtils.loadAnimation(getContext(), R.anim.shake);
editText.startAnimation(shake);
editText.setError(errorMessage);
}
private void startHomeActivityWithDelay() {
KeyboardUtils.hideKeyboard(requireContext(), getView());
// Delay starting the exit animation by 0.5 seconds
new Handler(Looper.getMainLooper()).postDelayed(() -> {
// Start the exit animation for the fragment
Animation exitAnimation = AnimationUtils.loadAnimation(getContext(), com.blogspot.atifsoftwares.animatoolib.R.anim.animate_slide_up_exit);
requireView().startAnimation(exitAnimation);
// Delay starting the Home activity to let the animation complete
new Handler(Looper.getMainLooper()).postDelayed(() -> {
Intent intent = new Intent(getContext(), Home.class);
startActivity(intent);
Animatoo.INSTANCE.animateSlideDown(requireContext());
// Remove the current fragment from the stack
requireActivity().getSupportFragmentManager().beginTransaction().remove(Login.this).commit();
// Re-enable main activity views
if (getActivity() instanceof MainActivity) {
((MainActivity) getActivity()).enableMainViews();
}
}, exitAnimation.getDuration());
}, 500); // Delay of 0.5 seconds (500 milliseconds)
}
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
updateIllustration(newConfig);
}
private void updateIllustration(Configuration config) {
if ((config.uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES) {
ivIllustrationLogin.setImageResource(R.drawable.login_illustration_dark);
} else {
ivIllustrationLogin.setImageResource(R.drawable.login_illustration);
}
}
private boolean isValidEmail(String email) {
return EMAIL_PATTERN.matcher(email).matches();
}
public static class KeyboardUtils {
public static void hideKeyboard(Context context, View view) {
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/785 ... -in-logcat
Ошибка Android Studio WindowManager system_server в Logcat ⇐ JAVA
Программисты JAVA общаются здесь
-
Anonymous
1716836803
Anonymous
Когда я перехожу от фрагмента входа в MainActivity Directly к Home Activity, внутри logcat возникает эта ошибка:
1742-2998 WindowManager system_server E win= Окно {b2e7c3a u0 com.example.synthshine_music/com.example.synthshine_music.MainActivity} DestroySurfaces: appStopped=true cleanupOnResume=false win.mWindowRemovalAllowed=false win.mRemoveOnExit=false win.mViewVisibility=8 caller=com.android.server.wm .ActivityRecord.destroySurfaces: 6862 com.android.server.wm.ActivityRecord.destroySurfaces: 6843 com.android.server.wm.ActivityRecord.activityStopped: 7510 com.android.server.wm.ActivityClientController.activityStopped: 310 android.app.IActivityClientController $Stub.onTransact:702 com.android.server.wm.ActivityClientController.onTransact:175 android.os.Binder.execTransactInternal:1380
Я предполагаю это связано с тем, как я управляю фрагментами, но понятия не имею,
Я новичок в разработке для Android и использовал GPT для значительной части своего проекта. Мой учитель не учил нас, как обращаться с фрагментами, и я предполагаю, что эта проблема возникает из-за этого. Мое приложение ни разу не вышло из строя, однако мне бы хотелось, чтобы эта ошибка была устранена.
Функция интересов, вероятно,
OnBackPressed в MainActivity
и StartActivityWithDelay во фрагменте входа в систему .
Вот мой код MainActivity:
package com.example.synthshine_music;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
public class MainActivity extends AppCompatActivity {
TextView tvAppName, tvNewUser;
ImageView ivIllustration;
Button btnLogIn;
FrameLayout flContainer;
int count = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
FragmentManager fragmentManager = getSupportFragmentManager();
if (fragmentManager.getBackStackEntryCount() > 0) {
fragmentManager.popBackStack();
enableMainViews(); // Enable main views when fragment is popped
tvNewUser.setEnabled(true);
} else {
finish(); // or super.onBackPressed();
}
}
});
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
tvAppName = findViewById(R.id.tvAppName);
tvNewUser = findViewById(R.id.tvNewUser);
ivIllustration = findViewById(R.id.ivIllustration);
btnLogIn = findViewById(R.id.btnLogIn);
flContainer = findViewById(R.id.flContainer);
tvAppName.setOnClickListener(v -> {
if (count == 5) {
Toast.makeText(MainActivity.this, "AMOLED Activated!", Toast.LENGTH_SHORT).show();
count = 0;
}
count++;
});
tvNewUser.setOnClickListener(v -> {
disableMainViews(); // Disable main views when fragment is shown
tvNewUser.setEnabled(false);
replaceFragment(new Register());
});
btnLogIn.setOnClickListener(v -> {
disableMainViews(); // Disable main views when fragment is shown
tvNewUser.setEnabled(false);
replaceFragment(new Login());
});
updateIllustration(getResources().getConfiguration());
}
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
updateIllustration(newConfig);
}
private void updateIllustration(Configuration config) {
if ((config.uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES) {
ivIllustration.setImageResource(R.drawable.illustration_dark);
} else {
ivIllustration.setImageResource(R.drawable.illustration);
}
}
// Method to enable or disable touch for main views
private void disableMainViews() {
tvAppName.setEnabled(false);
ivIllustration.setEnabled(false);
btnLogIn.setEnabled(false);
}
// Method to enable or disable touch for main views
void enableMainViews() {
tvAppName.setEnabled(true);
ivIllustration.setEnabled(true);
btnLogIn.setEnabled(true);
}
private void replaceFragment(Fragment fragment) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction().setCustomAnimations(R.anim.slide_lr, R.anim.slide_lr, R.anim.slide_rl, R.anim.slide_rl);
fragmentTransaction.replace(R.id.flContainer, fragment).addToBackStack(null);
fragmentTransaction.commit();
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
return super.dispatchTouchEvent(ev);
}
}
Фрагмент входа:
package com.example.synthshine_music;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.blogspot.atifsoftwares.animatoolib.Animatoo;
import com.google.android.material.textfield.TextInputEditText;
import java.util.Objects;
import java.util.regex.Pattern;
public class Login extends Fragment {
private static final String EMAIL_REGEX_PATTERN = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
private static final Pattern EMAIL_PATTERN = Pattern.compile(EMAIL_REGEX_PATTERN);
private TextInputEditText etEmail, etPassword;
private ImageView ivIllustrationLogin;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_login, container, false);
etEmail = view.findViewById(R.id.etEmail);
etPassword = view.findViewById(R.id.etPassword);
Button btnLogin = view.findViewById(R.id.btnLogInlogin);
ivIllustrationLogin = view.findViewById(R.id.ivIllustrationLogin);
btnLogin.setOnClickListener(v -> {
String email = Objects.requireNonNull(etEmail.getText()).toString();
String password = Objects.requireNonNull(etPassword.getText()).toString();
if (email.isEmpty()) {
showErrorWithAnimation(etEmail, "Email cannot be empty");
} else if (!isValidEmail(email)) {
showErrorWithAnimation(etEmail, "Invalid email");
} else if (password.isEmpty()) {
showErrorWithAnimation(etPassword, "Password cannot be empty");
} else if (password.length() < 8) {
showErrorWithAnimation(etPassword, "Password must be at least 8 characters long");
} else {
startHomeActivityWithDelay();
}
});
updateIllustration(getResources().getConfiguration());
return view;
}
private void showErrorWithAnimation(EditText editText, String errorMessage) {
Animation shake = AnimationUtils.loadAnimation(getContext(), R.anim.shake);
editText.startAnimation(shake);
editText.setError(errorMessage);
}
private void startHomeActivityWithDelay() {
KeyboardUtils.hideKeyboard(requireContext(), getView());
// Delay starting the exit animation by 0.5 seconds
new Handler(Looper.getMainLooper()).postDelayed(() -> {
// Start the exit animation for the fragment
Animation exitAnimation = AnimationUtils.loadAnimation(getContext(), com.blogspot.atifsoftwares.animatoolib.R.anim.animate_slide_up_exit);
requireView().startAnimation(exitAnimation);
// Delay starting the Home activity to let the animation complete
new Handler(Looper.getMainLooper()).postDelayed(() -> {
Intent intent = new Intent(getContext(), Home.class);
startActivity(intent);
Animatoo.INSTANCE.animateSlideDown(requireContext());
// Remove the current fragment from the stack
requireActivity().getSupportFragmentManager().beginTransaction().remove(Login.this).commit();
// Re-enable main activity views
if (getActivity() instanceof MainActivity) {
((MainActivity) getActivity()).enableMainViews();
}
}, exitAnimation.getDuration());
}, 500); // Delay of 0.5 seconds (500 milliseconds)
}
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
updateIllustration(newConfig);
}
private void updateIllustration(Configuration config) {
if ((config.uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES) {
ivIllustrationLogin.setImageResource(R.drawable.login_illustration_dark);
} else {
ivIllustrationLogin.setImageResource(R.drawable.login_illustration);
}
}
private boolean isValidEmail(String email) {
return EMAIL_PATTERN.matcher(email).matches();
}
public static class KeyboardUtils {
public static void hideKeyboard(Context context, View view) {
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78540613/android-studio-windowmanager-system-server-error-in-logcat[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия