如何从一个片段中开始的活动? [英] How do I start an activity from within a Fragment?

查看:120
本文介绍了如何从一个片段中开始的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组 FragmentActivity 里面的标签,每个持有自己的片段。当我试图通过 onClickListener ,并使用 startActivity(myIntent)方法来启动一个新的活动从片段中,我的应用程序的力量关闭。

I have a set of tabs inside of a FragmentActivity that each hold their own fragment. When I tried to start a new activity from within that fragment via an onClickListener, and using the startActivity(myIntent) method, my application force closes.

在东张西望了一会儿,我发现了一个参考或两个名为方法 startActivityFromFragment ,但摸索了一个小时左右,我找不到任何后如何使用它,或者这是否说明或例子是我应该使用。

After looking around for a while, I found a reference or two to a method called startActivityFromFragment, but after searching around for an hour or so I can't find any explanations or examples of how to use it or whether this is what I should be using.

我猜我问的是是否有从活动启动一个新的活动,并从片段推出一个新的活动有什么区别,如果是的话,需要什么来实现?

I guess what I'm asking is whether there is any difference between launching a new activity from an activity, and launching a new activity from a fragment, and if so, what do I need to implement?

推荐答案

您应该 getActivity()做到这一点。startActivity(myIntent)

这篇关于如何从一个片段中开始的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆