如何解决当我在登录和注册屏幕上单击任何 EditText 时设备重新启动
每次我点击密码或通过电子邮件 EditText 输入内容时,几秒钟后我的手机就会开始重启
我尝试了以下方法:
LoginActivity.java:
public class LoginActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FirebaseAuth mAuth = FirebaseAuth.getInstance();
final EditText email = findViewById(R.id.username);
final EditText password = findViewById(R.id.password);
final Button login_btn = findViewById(R.id.login_btn);
final ProgressBar loading_bar = findViewById(R.id.progressBar);
final TextView signup = findViewById(R.id.textView4);
final TextView reset_password = findViewById(R.id.textView38);
loading_bar.setVisibility(View.GONE);
reset_password.setonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(LoginActivity.this,PasswordResetActivity.class));
}
});
login_btn.setonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loading_bar.setVisibility(View.VISIBLE);
String email_input = email.getText().toString();
String password_input = password.getText().toString();
if (email_input.isEmpty() || password_input.isEmpty()){
Toast.makeText(LoginActivity.this,"Please fill all the values!",Toast.LENGTH_SHORT).show();
loading_bar.setVisibility(View.GONE);
}else{
mAuth.signInWithEmailAndPassword(email_input,password_input).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull @NotNull Task<AuthResult> task) {
if (email_input.isEmpty() || password_input.isEmpty()){
Toast.makeText(LoginActivity.this,Toast.LENGTH_SHORT).show();
}else{
if (task.isSuccessful()){
// user has logged in successfully \\
finish();
startActivity(new Intent(LoginActivity.this,HomeActivity.class));
}else{
// user is not logged in \\
loading_bar.setVisibility(View.GONE);
Toast.makeText(LoginActivity.this,"Wrong email or password.
Please check your information and try again",Toast.LENGTH_SHORT).show();
}
}
}
});
}
}
});
signup.setonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(LoginActivity.this,SignupActivity.class));
}
});
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".LoginActivity"
android:background="@drawable/background">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView38"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Reset your password"
android:clickable="true"
android:focusable="true"
android:textColor="@color/white"
android:textSize="17sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/textView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/login_btn" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="172dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="181dp"
android:layout_marginBottom="614dp"
android:text="@string/app_name"
android:textColor="@color/white"
android:textSize="40sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.19999999" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:layout_marginBottom="50dp"
android:gravity="center"
android:padding="10dp"
android:text="Sign in to your SM account to laugh as much as you want for free"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/username"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="0.0" />
<EditText
android:id="@+id/username"
android:layout_width="266dp"
android:layout_height="41dp"
android:layout_marginTop="32dp"
android:background="@drawable/et_style"
android:elevation="15dp"
android:ems="10"
android:gravity="center"
android:hint="email address"
android:inputType="textPersonName"
android:textColor="@color/black"
android:textColorHint="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<EditText
android:id="@+id/password"
android:layout_width="266dp"
android:layout_height="41dp"
android:layout_marginTop="20dp"
android:background="@drawable/et_style"
android:ems="10"
android:hint="password"
android:elevation="15dp"
android:textColor="@color/black"
android:textColorHint="@color/black"
android:gravity="center"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/username" />
<Button
android:id="@+id/login_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginBottom="50dp"
android:background="@drawable/default_btn_style"
android:elevation="15dp"
android:text="Sign in to SM account"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/textView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/password" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="90dp"
android:text="new to social meme?"
android:textColor="@color/white"
android:textSize="17sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/login_btn" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="create an account"
android:textColor="@color/white"
android:textStyle="bold"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3"
app:layout_constraintVertical_bias="0.0" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/centerDark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/loading_icon_style"
android:elevation="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.909" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.george.socialmeme">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/app_logo"
android:label="@string/app_name"
android:roundIcon="@drawable/app_logo"
android:supportsRtl="true"
android:theme="@style/Theme.socialMeme">
<activity android:name=".LoginActivityT"/>
<activity android:name=".FeedbackActivity" />
<activity android:name=".PasswordResetActivity" />
<activity android:name=".BugReportActivity" />
<activity android:name=".ChangePasswordActivity" />
<activity android:name=".SecurityActivity" />
<activity android:name=".ChangeEmailActivity" />
<activity android:name=".ChangeUsernameActivity" />
<activity android:name=".AccountinformationActivity" />
<activity android:name=".UploadPostActivity" />
<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings" />
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".HomeActivity" />
<activity android:name=".SignupActivity" />
<activity android:name=".LoginActivity" />
</application>
</manifest>
我的日志:
2021-03-04 21:15:31.328 12812-12812/com.george.socialmeme I/ViewRootImpl@f8a674d[LoginActivityT]:
ViewPostIme pointer 0
2021-03-04 21:15:31.424 12812-12812/com.george.socialmeme I/ViewRootImpl@f8a674d[LoginActivityT]:
ViewPostIme pointer 1
2021-03-04 21:15:31.455 12812-12812/com.george.socialmeme D/Toast: show: focusdisplayId = 0,isFocusInDesktop = false mCustomdisplayId=-1
2021-03-04 21:15:31.465 12812-25564/com.george.socialmeme V/Toast: SHOW:
android.widget.Toast$TN@1a4c799
2021-03-04 21:15:31.468 12812-12812/com.george.socialmeme V/Toast: HANDLE SHOW:
android.widget.Toast$TN@1a4c799 mView=null mNextView=android.widget.LinearLayout{14fca5e V.E......
......I. 0,0-0,0}
2021-03-04 21:15:31.468 12812-12812/com.george.socialmeme V/Toast: HANDLE HIDE:
android.widget.Toast$TN@1a4c799 mView=null
2021-03-04 21:15:31.481 12812-12812/com.george.socialmeme I/ViewRootImpl@cf14455[Toast]: setView =
android.widget.LinearLayout@14fca5e TM=true MM=false
2021-03-04 21:15:31.481 12812-12812/com.george.socialmeme V/Toast: Text: Qlea in
android.widget.Toast$TN@1a4c799
2021-03-04 21:15:31.493 12812-12812/com.george.socialmeme I/ViewRootImpl@cf14455[Toast]: Relayout
returned: old=(0,79,1080,2274) new=(283,1990,797,2106) req=(514,116)0 dur=7 res=0x7 s={true
480379101184} ch=true
2021-03-04 21:15:31.495 12812-25565/com.george.socialmeme D/Openglrenderer: createReliableSurface :
0x6fd8bf6f40(0x6fd8d36000)
2021-03-04 21:15:31.495 12812-25565/com.george.socialmeme D/Surface:
Surface::connect(this=0x6fd8d36000,api=1)
2021-03-04 21:15:31.496 12812-25565/com.george.socialmeme D/mali_winsys: EGLint
new_window_surface(egl_winsys_display *,void *,EGLSurface,EGLConfig,egl_winsys_surface **,EGLBoolean) returns 0x3000
2021-03-04 21:15:31.496 12812-25565/com.george.socialmeme D/Openglrenderer: eglCreateWindowSurface :
0x6fd9c5e000
2021-03-04 21:15:31.496 12812-25565/com.george.socialmeme D/Surface:
Surface::setBufferCount(this=0x6fd8d36000,bufferCount=3)
2021-03-04 21:15:31.496 12812-25565/com.george.socialmeme D/Surface:
Surface::allocateBuffers(this=0x6fd8d36000)
2021-03-04 21:15:31.499 12812-25565/com.george.socialmeme D/Openglrenderer: makeCurrent EglSurface :
0x6fd9c5e700 -> 0x6fd9c5e000
2021-03-04 21:15:31.522 12812-25565/com.george.socialmeme D/Openglrenderer: makeCurrent EglSurface :
0x6fd9c5e000 -> 0x6fd9c5e700
2021-03-04 21:15:31.537 12812-12812/com.george.socialmeme I/ViewRootImpl@cf14455[Toast]: MSG_RESIZED:
frame=(283,2106) ci=(0,0) vi=(0,514,116) or=1
2021-03-04 21:15:33.466 12812-25564/com.george.socialmeme V/Toast: HIDE:
android.widget.Toast$TN@1a4c799
2021-03-04 21:15:33.467 12812-12812/com.george.socialmeme V/Toast: HANDLE HIDE:
android.widget.Toast$TN@1a4c799 mView=android.widget.LinearLayout{14fca5e V.E...... ........ 0,0-
514,116}
2021-03-04 21:15:33.467 12812-12812/com.george.socialmeme V/Toast: REMOVE!
android.widget.LinearLayout{14fca5e V.E...... ........ 0,0-514,116} in
android.widget.Toast$TN@1a4c799
2021-03-04 21:15:33.472 12812-25565/com.george.socialmeme D/Openglrenderer: destroyEglSurface :
0x6fd9c5e000
2021-03-04 21:15:33.474 12812-25565/com.george.socialmeme D/Surface:
Surface::disconnect(this=0x6fd8d36000,api=1)
2021-03-04 21:15:33.476 12812-25565/com.george.socialmeme D/Openglrenderer: ~ReliableSurface :
0x6fd8bf6f40
2021-03-04 21:15:33.477 12812-12812/com.george.socialmeme I/ViewRootImpl@cf14455[Toast]:
dispatchDetachedFromWindow
2021-03-04 21:15:33.488 12812-12812/com.george.socialmeme D/InputTransport: Input channel destroyed:
'30571db',fd=99
2021-03-04 21:15:41.261 12812-12812/com.george.socialmeme I/ViewRootImpl@f8a674d[LoginActivityT]:
ViewPostIme pointer 0
2021-03-04 21:15:41.321 12812-12812/com.george.socialmeme I/ViewRootImpl@f8a674d[LoginActivityT]:
ViewPostIme pointer 1
2021-03-04 21:15:41.339 12812-12812/com.george.socialmeme D/InputMethodManager:
prepareNavigationBarInfo() DecorView@258009f[LoginActivityT]
2021-03-04 21:15:41.339 12812-12812/com.george.socialmeme D/InputMethodManager:
getNavigationBarColor() -855310
2021-03-04 21:15:41.339 12812-12812/com.george.socialmeme V/InputMethodManager: Starting input:
tba=com.george.socialmeme ic=com.android.internal.widget.EditableInputConnection@c90f52f
mNaviBarColor -855310 mIsGetNaviBarColorSuccess true,NavVisible : true,NavTrans : false
2021-03-04 21:15:41.339 12812-12812/com.george.socialmeme D/InputMethodManager: startInputInner - Id
: 0
2021-03-04 21:15:41.349 12812-12812/com.george.socialmeme I/InputMethodManager: startInputInner -
mService.startInputOrWindowGainedFocus
2021-03-04 21:15:41.353 12812-12812/com.george.socialmeme D/InputTransport: Input channel destroyed:
'ClientS',fd=95
2021-03-04 21:15:41.353 12812-12812/com.george.socialmeme D/InputMethodManager: SSI - flag : 0 Pid :
12812 view : com.george.socialmeme
2021-03-04 21:15:41.353 12812-12812/com.george.socialmeme D/InputMethodManager:
prepareNavigationBarInfo() DecorView@258009f[LoginActivityT]
2021-03-04 21:15:41.353 12812-12812/com.george.socialmeme D/InputMethodManager:
getNavigationBarColor() -855310
2021-03-04 21:15:41.358 12812-12812/com.george.socialmeme D/Editor: waiting for the right moment
2021-03-04 21:15:41.368 12812-12812/com.george.socialmeme I/AssistStructure: Flattened final assist
data: 2276 bytes,containing 1 windows,10 views
2021-03-04 21:15:41.432 12812-12812/com.george.socialmeme I/ViewRootImpl@f8a674d[LoginActivityT]:
MSG_RESIZED: frame=(0,2400) ci=(0,867) vi=(0,867) or=1
2021-03-04 21:15:41.471 12812-12812/com.george.socialmeme I/ViewRootImpl@f8a674d[LoginActivityT]:
Relayout returned: old=(0,2400) new=(0,2400) req=(1080,2400)0 dur=16 res=0x1 s={true
480395943936} ch=false
2021-03-04 21:15:41.479 12812-12812/com.george.socialmeme D/ScrollView: onsize change changed
解决方法
我已经在不同的设备上测试了整个代码,物理的和模拟的,似乎没有问题。似乎是您特定设备的问题,可能与您的代码无关。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。