如何从非活性类停止活动? [英] How to stop an activity from a non-activity-class?
问题描述
我有一个问题:我有一个导航抽屉的应用程序。所以,我已经得到了DetailFragment.java类:
@TargetApi(Build.VERSION_ codeS.HONEYCOMB)
公共类DetailFragment扩展片段{的FrameLayout fLayout;查看视图。
上下文videoContext;
上下文语境;公共DetailFragment(){
}@覆盖
公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,捆绑参数){
鉴于= inflater.inflate(R.layout.menu_detail_fragment,集装箱,FALSE);
路线菜单= getArguments()的getString(菜单)。 开关(菜单){
案(家):{
fLayout =(的FrameLayout)view.findViewById(R.id.home);
fLayout.setVisibility(View.VISIBLE);
打破;
} 案(信息):{
fLayout =(的FrameLayout)view.findViewById(R.id.info);
fLayout.setVisibility(View.VISIBLE);
打破;
} 案(视频):{
startActivity(新意图(getActivity(),VideoActivity.class));
打破;
}
} 返回视图。
}
}
您看,在第三的情况下视频,我开始一个活动女巫播放视频。但是,当我点击的开关结构另一个按钮,活动的背景和视频运行了。如何停止在其他情况下,语句的活动,以便视频没有在后台运行了吗?
感谢您的帮助,
康斯坦丁。
PS:对不起,我英文不好,我只有12日和德国:)
如果(getActivity()。class.getSimpleName ==VideoActivity)
((活动)getActivity()),完成();
这行每个案件应该这样做。
I've got a problem: I've got an app with a Navigation-Drawer. So I've got the DetailFragment.java class:
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class DetailFragment extends Fragment {
FrameLayout fLayout;
View view;
Context videoContext;
Context context;
public DetailFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle args) {
view = inflater.inflate(R.layout.menu_detail_fragment, container, false);
String menu = getArguments().getString("Menu");
switch (menu) {
case ("Home"): {
fLayout = (FrameLayout) view.findViewById(R.id.home) ;
fLayout.setVisibility(View.VISIBLE);
break;
}
case ("Info"): {
fLayout = (FrameLayout) view.findViewById(R.id.info) ;
fLayout.setVisibility(View.VISIBLE);
break;
}
case ("Video"): {
startActivity(new Intent(getActivity(), VideoActivity.class));
break;
}
}
return view;
}
}
You see, in the 3rd case 'Video', I start an Activity witch play a video. But when I click on another Button in the Switch-Structure, the Activity runs in background and the video too. How can I stop the activity in the other Case-Statements so the Video is not running in background any more?
Thank you for any help, Konstantin.
PS: Sorry for my bad English, I'm only 12 and from Germany :)
if(getActivity().class.getSimpleName=="VideoActivity")
((Activity)getActivity()).finish();
This line in each of the cases should do it.
这篇关于如何从非活性类停止活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!