Killing one activity from another

前端 未结 4 1610
后悔当初
后悔当初 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:03

    Create static Class variable to save the instance: static SampleActivity sampleActivity;

    On Create of first Activity save the Instance, like this: incidenteActivity = this;

    Create a static method to get the instance:

    public static SampleActivity getInstance(){
        return   sampleActivity;
    }
    

    wherever you want call:

    SampleActivity.getInstance().finish();
    

    it really works, regards,

提交回复
热议问题