Question: I have an Activity ListActivity having Listview and another class CustomListAdapter extends BaseAdapter. 

Code in ListActivity 

```
customAdapter = new CustomListAdapter(list);
TripList.setAdapter(customAdapter);

```

In getView() of CustomListAdapter I inflate a layout. there is a button and on click of that button I am starting another activity. 

I want to finish ListActivity after start of another activity.
With the below code My app is crashing.

```
((Activity) ctx).finish();

```

Log is

```
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)

```

Please Help me out.

Answer: 
At first ,You can post your  `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.
> 
> 
> 

You can use `Intent.FLAG_ACTIVITY_CLEAR_TOP |Intent.FLAG_ACTIVITY_NEW_TASK`

**Finally** ,It should be ,

```
   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);

```
As i was starting an activity inside getView() so
`((Activity) ctx).finish();` was not working. I just changed it to `((Activity)parent.getContext()).finish();` and it was working