aasg
aasg

Reputation: 33

How to Close an Intent Activity from another Class

Basically I'm using the following code to open Google Navigation within an activity

 String uri = "google.navigation:ll="+LAT+","+LNG;
                    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                    startActivity(i); 

Where LAT & LNG are the coordinates of a specific destination. Basically what I'm trying to do is once the destination is reached, an action would be triggered where the navigation activity closes and return to the same Class it was opened in.

Any help would be much appreciated.

EDIT: i guess since the activity i opened "Google Navigation" is beyond my control it is impossible to close it from within the app. So the best solution would be to reopen the current activity once the destination is reached.

Appreciate all the answers.

Upvotes: 3

Views: 7359

Answers (7)

payal tuteja
payal tuteja

Reputation: 170

Use finish() method to end the first activity

Upvotes: 2

Pankaj Arora
Pankaj Arora

Reputation: 10274

use Finish() method to kill your activity as

 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));

startActivity(intent);

finish();

Upvotes: 1

Hubert
Hubert

Reputation: 1

Maybe you should put a thread to compare the destination and current location. Like this:

Thread thread = new Thread(){
    @Override
    public void run() {
        // TODO: Do your work here
        myHandler.sendMessage(new Message());
    }
};

create a handler and implementing the handleMessage method.

Handler myHandler = new Handler(){
    @Override
    public void handleMessage(Message msg) {
        // TODO: finish the activity here
        finish();
    }
};

Upvotes: 0

Metalhead1247
Metalhead1247

Reputation: 1978

If you press your back button it will work !! don't finish() the previous activity. Dont call finish() when you are starting the intent. Once you finish with navigation press back button

Upvotes: 0

RobinHood
RobinHood

Reputation: 10969

Add Finish() method to end up an activity@

 Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);
finish();

Upvotes: 0

Pratik Dasa
Pratik Dasa

Reputation: 7439

Use finish() to kill the activity.

Upvotes: 0

Hybrid Developer
Hybrid Developer

Reputation: 2340

Use finish() method to end an activity

Upvotes: 0

Related Questions