Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Android how to close/finish an activity

$
0
0

I am trying to give users the ability to open up the wifi settings directly from my app if their wifi connection gets lost at any point. To do this I am just simply popping up an alert that gives them the option to open the wifi settings screen, and then using an intent to open it if they choose yes. I've got that part working so far.

The issue I'm facing is that when I get to the wifi settings screen I am trying to automatically close it once a connection is re-established, but Ti.Android.currentActivity is still stuck on android.intent.action.MAIN so I can't call finish() on this new activity and the user ends up being stuck on the wifi screen at this point. Pressing the back button on the action bar is not an option in my case (this is a kiosk app so the home and back buttons are hidden behind a metal case).

Any insight into why my currentActivity doesn't change once I start a new activity would be greatly appreciated! I'm new to Android intents so I could just be overlooking something... or maybe I'm on a wild goose chase here and there's a different way to accomplish this.

var noConnectionAlert = Titanium.UI.createAlertDialog({
        title: "Check Your Connection",
        message: "Whoops! It looks like the tablet has lost it's connection to the Internet. Please check your wifi settings.",
        cancel: 1,
        buttonNames: ['Open Wifi Settings', 'Cancel'],
    });
 
    var wifiIntent = Ti.Android.createIntent({action: "android.settings.WIFI_SETTINGS"});
 
    noConnectionAlert.addEventListener('click', function(e) {
        // Open the wifi settings with an android intent
        if (e.index === 0) {
            Ti.Android.currentActivity.startActivity(wifiIntent);
        }
    });
 
    Ti.Network.addEventListener('change', function(e) {
        if (!e.online) {
            noConnectionAlert.show();   
        }
        else {
            // Connection is re-established.
            // Do something to close the wifi settings screen if it's open.
        }
    }

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>