Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : Calling Activity from Fragment

I am using fragments inside an activity. I am using MediaRecorder to for audio recording. I have two part of an activity. 1st itself the Activity which will list the recorded file. On it's right side the AudioRecording Activity is called when one select to record for a new file. When the any of the listed file is selected i am using AudioPlayer as to play the recorded file. I am here able to convert the Activity into fragment but when i press on Stop it is terminating the application.

Please anyone can answer. My audiorecorder is working fine when i use it as simple activity. Any solution like if i can call that activity in that fragment or something like that.? Please help me if anyone knows.

like image 740
Dharma Cool Avatar asked Sep 28 '12 09:09

Dharma Cool


People also ask

Can we call activity from fragment in Android?

Best way of calling Activity from Fragment class is that make interface in Fragment and add onItemClick() method in that interface. Now implement it to your first activity and call second activity from there.

How can we call parent activity from fragment?

Simply call your parent activity using getActivity() method.

Can we start activity from fragment?

If you make it a Fragment then change findViewById to v. findViewById . There is no findViewById function in Fragment so you have to call getView first then call findViewById on that. In your case though, you already have your view in onCreateView and that would be your variable v .


1 Answers

Get the parent activity using get activity then do as usual.

Intent myIntent = new Intent(getActivity().getapplicationcontext(), BookmarkActivity.class);
getActivity().startActivity(myIntent); 
like image 178
Chinmoy Debnath Avatar answered Oct 25 '22 09:10

Chinmoy Debnath