朱纯树博客
VPS测评推荐网站
cloudacead cloudacead

安卓自定义视图非activity使用Intent跳转任意activity的实现方式

需求是这个样子的:我写了一个小游戏,并且我创建了一个自定义的View

image-20201204081606117

现在,我需要在游戏结束之后跳转到另一个activity

image-20201204081822930

我们使用常规的跳转方式,会发现自定义的View根本没有startActivity()这个方法

image-20201204082223814

那么,我们如何解决这个问题?

其实很简单,我们只需要获取当前view的context即可,使用context的方法来启动新的activity

Intent intent = new Intent(getContext(),GameOverActivity.class);
            getContext().startActivity(intent);

注意,这里是无法使用finish()方法来销毁activity的。

image-20201204082617181

文章来源于互联网:安卓自定义视图非activity使用Intent跳转任意activity的实现方式

赞(0) 打赏
未经允许不得转载:VPS测评推荐网站 - 朱纯树博客 » 安卓自定义视图非activity使用Intent跳转任意activity的实现方式

评论 37

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #45

    Blessed is Your Name, there is no true God but You cialis on sale in usa

    PyncSnody3周前 (03-06)回复
  2. #44

    buying cialis online safe If possible, steps should be taken to limit the number of medications to those most effective for the patient

    Kigngoore3周前 (03-06)回复
  3. #43

    Other considerations for nephrotoxin management cialis online generic Maca has also been shown to significantly increase testosterone levels

    Wrotoub2个月前 (02-09)回复
  4. #42

    Take a small dose 25mg, 50mg purchase zithromax for chlamydia

    Galgari2个月前 (02-09)回复
  5. #41

    PubMed 18496468 lasix 40 mg tablet

    Feeklydak2个月前 (02-03)回复
  6. #40

    It s been over a week since I ovulated cialis buy

    Cimamoife2个月前 (02-03)回复
  7. #39

    We do know that tamoxifen increases endometrial cancer by two to three fold; there is emerging evidence that the anti estrogenic properties of anastrozole actually reduce endometrial cancer buy cialis online 20mg Garcia FG, Marco MA, Vela J, et al

    Layepaime2个月前 (01-28)回复