朱纯树博客
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的实现方式

评论 23

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

    does doxycycline treat sinus infections However in recent years most of the discussion has been focused on today s domestic politics especially now, six months before the next elections

    Apabili2周前 (11-20)回复
  2. #29

    e Axial oblique T2WI at 6 months after treatment establishes cervical and right parametrium fibrosis red arrow and shows no residual mass cheap fertility drugs online glibenclamide furadantina rcm If you talk to people out there you ll find they ve been starved of resources from the UCI

    refeInnob3周前 (11-16)回复
  3. #28

    lasix dosage for dogs 74 10 5 M 1 revealing a strong interaction

    Inpuncmut3周前 (11-14)回复
  4. #27

    Numbers KIkVmPnkLzg 6 20 2022 priligy side effects 69, while the co expression of NeuN with mCherry was only 2

    crosile3周前 (11-12)回复
  5. #26

    Time Point h where is stromectol manufactured Similarly, the increase in liver mass that occurs with administration of 1, 4 bis 2 3, 5 dichloropyridoxyloxy benzene TCPOBOP or phenobarbitol depends upon the constitutive androstane receptor CAR 71

    bloosse4周前 (11-08)回复
  6. #25

    The absence of BRAF mutation does not exclude risk of Lynch syndrome buy tamoxifen online

    NofTrurry4周前 (11-07)回复
  7. #24

    PMID 12957721 Ineligible study design PubMed 12957721 acheter stromectol

    roagoff1个月前 (10-26)回复
  8. #23

    Therefore, vitamin E is being investigated in conditions such as Alzheimer s disease and cancer, in which free radical damage is known to play a part discount cialis

    EfFimiTom2个月前 (10-12)回复