how can I finish activity from view
android, java, view
Solution
Since the `Context` you are using is the `Activitys context, you can cast the view`s context to Activity and call finish() upon it.
For instance:
private void finishFunction() {
Activity activity = (Activity)getContext();
activity.finish();
}
Probably it is not the best choice from the design perspective
Problem
I have got an activity which has custom view. I have to add activity result: ``` public class ActView extends Activity implements OnClickListener { <...code...> @Override protected void onCreate(Bundle savedInstanceState) { <...code...> layout = (LinearLayout) findViewById(R.id.chart_container); timelineview = new VDrawTimeLine(this,contentFull); timelineview.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); timelineview.setBackgroundColor(0xffffffff); timelineview.setVisibility(View.VISIBLE); layout.addView(timelineview); <...code...> } } ``` View class: ``` public class VDrawTimeLine extends View implements OnTouchListener{ <...code...> public VDrawTimeLine(Context context, ArrayList<_MainData> contentFull) { super(context); this.con = context; this.content = contentFull; <...code...> } } @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub finishFunction();//I need here finish event this activity result for ActView Activity. return true; } ``` finishFunction - what i have to write here to finish the ActView with the result for parent activity? I need somethin like this: ``` Intent intent = new Intent(); intent.putExtra(dataname, value); setResult(RESULT_OK,intent); finish(); ```