Launch main Android activity?


This is going to sound utterly noobish, but I’m having a hard time converting this code to TS:

startActivity(new Intent(this, MainActivity.class));

If I can get to a specific route within Angular, even better, but I’ll settle for just launching the NativeScript main activity for now! (I’m trying to launch the app when a certain push notification comes in)


Where exactly you are going to write this launch code?
Are you using Firebase and the custom messaging service?


Yes, in the message received callback, as suggested in:


Anybody? I’ll try to figure it out in the meanwhile, but any help would be appreciated. I am not sure how to represent “MainActivity.class” in Javascript.


I’m not sure if this works, give a try to


It works if the app is in the background, but it’s undefined when the app is in a terminated state. I tried to access com.tns.NativeScriptActivity.getClass() but that didn’t work either.


Then you will have to use fully qualified package name get the launch activity.


Awesome. I got it mostly working, so I’ll paste it here to help others.

private launchBackgroundedApp() {
        if ( {
            const startActivity: =;
            const context: android.content.Context =;
            let intent: android.content.Intent;
            if (startActivity) {
                intent = new android.content.Intent(context, startActivity.getClass());
                const pendingIntent =, 0, intent, 0);
                pendingIntent.send(context, 0, intent);
            } else {
                console.log("App is in a terminated state, relaunching...");

                const pm = context.getPackageManager();
                const packageName = "com.xxxx.xxxx";
                intent = pm.getLaunchIntentForPackage(packageName);

                if (intent) {
                    console.log("Intent could not be created for", packageName);

It works perfectly if the app is running in the background. If the user swipes the app away, it will relaunch the app, but I’m thinking it creates a different instance of it, even with android:launchMode="singleInstance" set in the Android manifest. Because if I do:


It won’t navigate in the case of the latter launch.


Figured it out. I extended the NativeScript activity and in the onCreate method accessed an extra (serialized string) that I injected via intent.putExtra(...) (before calling startActivity). Then, I wrote a singleton / static class to update some initial data onCreate, at which point I dynamically updated Angular’s starting route (so that it launches right into my alert page depending on the state of the initial data). :grinning: