virho
virho

Reputation: 149

Close activity from service

How to close an Activity from a service. Here's my code in service

public void run() {             
    Date dt = new Date();
    int minutes = dt.getMinutes();
    if (minutes % 2 == 0) {
        stopThread();
        Intent i = new Intent();
        i.setClass(this, show_act.class); 
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(i);    
    }
    else{ 
       //what must i do,. How to close show_act activities from service     
    }
}

Please help me solve this . .

Upvotes: 2

Views: 2455

Answers (1)

Vincent Mimoun-Prat
Vincent Mimoun-Prat

Reputation: 28541

In your activity's onResume function, register a broadcast receiver that will call the activity's finish() method.

In your service, when you want to close the activity, simply send the broadcast. If the activity is currently shown, the broadcast receiver will call its finish() method.

Upvotes: 2

Related Questions