Killing one activity from another

前端 未结 4 1611
后悔当初
后悔当初 2021-01-02 05:33

I have two activities A and B. B is a transparent pass through activity, and A is seen. I want to kill B by pressing a button A.

Here\'s what I\'ve tried so far:

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-02 06:04

    I found a nice way to finish one activity from another, it is similar to what Lumis did. So if you want to close ActivityA from ActivityB you can do this:

    In ActivityA do:

    className = this.getClass().getName();
    

    and pass it on to AvtivityB. Then in ActivityB do:

    ((Activity) Class.forName(className).newInstance()).finish();
    

    You can put a string with the name of your class into className yourself, but it needs to be a full name with package too.

提交回复
热议问题