我有一个具有 Listview 的 Activity ListActivity,另一个类 CustomListAdapter 扩展了 BaseAdapter。
ListActivity 中的代码
customAdapter = new CustomListAdapter(list);
TripList.setAdapter(customAdapter);
在 CustomListAdapter 的 getView() 中,我膨胀了一个布局。有一个按钮,单击该按钮我将开始另一项 Activity 。
我想在另一个 Activity 开始后完成 ListActivity。 使用以下代码我的应用程序崩溃了。
((Activity) ctx).finish();
日志是
01-05 11:06:04.319: E/AndroidRuntime(4319): FATAL EXCEPTION: main
01-05 11:06:04.319: E/AndroidRuntime(4319): Process: com.example.myapp, PID: 4319
01-05 11:06:04.319: E/AndroidRuntime(4319): java.lang.NullPointerException
01-05 11:06:04.319: E/AndroidRuntime(4319): at com.example.myapp.CustomListAdapter$1.onClick(CustomListAdapter.java:71)
请帮帮我。
最佳答案
首先,您可以发布您的 Logcat 。
FLAG_ACTIVITY_CLEAR_TOP
If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.
FLAG_ACTIVITY_NEW_TASK
if used to start the root activity of a task, it will bring any currently running instance of that task to the foreground, and then clear it to its root state.
您可以使用Intent.FLAG_ACTIVITY_CLEAR_TOP |Intent.FLAG_ACTIVITY_NEW_TASK
最后,应该是,
Intent intent = new Intent(ctx, NewActivityName.Class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
关于android - 在另一个 Activity 开始后单击 Listview 按钮完成或销毁 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34607021/