【发布时间】:2021-05-04 19:04:19
【问题描述】:
我正在努力解决这个问题:活动应该开始,但在使用 putExtra 时却没有。唯一发生的事情是我看到 Fragment 在右侧滑动(出现故障后),然后应用程序崩溃了。请注意,此 Fragment 是 Navigation 组件的一部分。这是我的代码,在 onClick 方法中:
Intent intent = new Intent(v.getContext(), SecondActivity.class);
intent.putExtra("ID", ID);
v.getContext().startActivity(intent);
Log.w("here", "should have started");
其中“v”是我单击的 RecyclerView 的视图。这是点击后不久出现在 Logcat 上的内容:
V/AudioManager: querySoundEffectsEnabled...
W/here: should have started
V/FA: Recording user engagement, ms: 7695
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@b33fd52
V/FA: Connecting to remote service
V/FA: Activity paused, time: 295957791
当我重新打开应用程序时,它会从 MainActivity(开始)重新启动。如果我评论 putExtra 行,SecondActivity 就会启动,这是一个非常奇怪的行为。任何帮助将不胜感激! :)
【问题讨论】:
-
你需要发布堆栈跟踪的logcat,这个信息没有用
标签: android android-fragments android-intent android-activity