gpt4 book ai didi

android - OnResume 之后立即调用 OnPause

转载 作者:太空宇宙 更新时间:2023-11-03 11:01:43 25 4
gpt4 key购买 nike

编辑* 在 Android 设备上测试时出现此问题。在 emultor 上测试时不会出现此问题。


我正在开始一项新 Activity ,我看到在调用 onResume 之后立即调用了 onPause。如果我查看日志,它会在 onResume 之后进入空闲状态。因此在调用 onResume 后立即导致 onPause。

调用方 Activity - 通过 Intent 在 onClick 上调用 MainActivity。

public class TestActivity extends AppCompatActivity implements View.OnClickListener{

String TAG = "acr";
Button testBtn;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
testBtn = (Button) findViewById(R.id.testBtn);
testBtn.setOnClickListener(this);
}

@Override
protected void onPause() {
super.onPause();
Log.i(TAG, "on pause called on TestActivity ");
}

@Override
protected void onResume() {
super.onResume();
Log.i(TAG, "on resume called on TestActivity ");
}

@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.testBtn:
Intent mainIntent = new Intent(this, MainActivity.class);
TestActivity.this.startActivity(mainIntent);
break;
}
}
}

有错误的 Activity

public class MainActivity extends AppCompatActivity{

public static final String TAG = "acrx";


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}


@Override
protected void onPause() {
super.onPause();
Log.i(TAG, "on pause called on mainactivity");
}

@Override
protected void onResume() {
super.onResume();
Log.i(TAG, "on resume Called on Main activity");
}

@Override
protected void onStop() {
super.onStop();
Log.i(TAG, "on stop Called on Main activity");
}
}

日志

12-06 23:24:19.751 22983-22983/com.example.m1alesis.smartcardreader I/acrx: on resume Called on Main activity
12-06 23:24:19.751 22983-22983/com.example.m1alesis.smartcardreader D/SecWifiDisplayUtil: Metadata value : SecSettings2
12-06 23:24:19.751 22983-22983/com.example.m1alesis.smartcardreader D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{5ce8491 I.E...... R.....ID 0,0-0,0}
12-06 23:24:19.781 22983-23012/com.example.m1alesis.smartcardreader D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000, [1440x2560]-format:1
12-06 23:24:19.811 22983-22983/com.example.m1alesis.smartcardreader W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
12-06 23:24:19.831 22983-22983/com.example.m1alesis.smartcardreader D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=1
12-06 23:24:19.871 22983-23012/com.example.m1alesis.smartcardreader D/OpenGLRenderer: endAllActiveAnimators on 0x7f9c17ec00 (RippleDrawable) with handle 0x7f9ccc8b60
12-06 23:24:19.871 22983-22983/com.example.m1alesis.smartcardreader I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@fa2f707 time:376798424
12-06 23:24:20.131 22983-22983/com.example.m1alesis.smartcardreader V/ActivityThread: updateVisibility : ActivityRecord{e78cff6 token=android.os.BinderProxy@a67fd36 {com.example.m1alesis.smartcardreader/com.example.m1alesis.smartcardreader.TestActivity}} show : false
12-06 23:24:31.561 22983-22983/com.example.m1alesis.smartcardreader I/acrx: on pause called on mainactivity
12-06 23:24:31.701 22983-22983/com.example.m1alesis.smartcardreader I/acrx: on resume Called on Main activity
12-06 23:24:31.721 22983-22983/com.example.m1alesis.smartcardreader I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@fa2f707 time:376810271

最佳答案

我有同样的问题,对我来说,它与 Activity 启动和屏幕不亮有关 - 我只是在我关闭屏幕后才看到它(例如,在触摸电源按钮然后回到家以再次恢复后) .

这是其他人也看到的行为 - 我发现这个问题和答案有有用的引用:OnPause and OnStop() called immediately after starting activity

帮助我理解该行为的关键引用是:

Keep in mind that onResume is not the best indicator that your activity is visible to the user; a system window such as the keyguard may be in front. Use onWindowFocusChanged(boolean) to know for certain that your activity is visible to the user

关于android - OnResume 之后立即调用 OnPause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41006884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com