0

I am trying to get this Service to open another app upon start up using the URI in the code. My BroadcastReciever and manifest have the correct code so I suspect it is something in this mainActivity.

I am using Eclipse and there are no errors or warning but when run on the phone i get the following error:

Unfortunately anyConnectService has stopped

The LogCat has the following as the first error:

FATAL EXCEPTION MAIN
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.anyconnect/com.anyconnectservice,MainActivity}

Please glance at the following code and offer a solution.

Thanks

public abstract class MainActivity extends Service
{
    @override
    public void onCreate()
    {
        super.onCreate();
        Toast.makeText(this, “Service created”,Toast.LENGTH_LONG).show();

        Uri anyConnectUri = Uri.parse(“anyconnect://connect/name= TestVPN”);
        Intent arg0 = new Intent(Intent.ACTION_VIEW, anyConnectUri);
        this.startActivity(arg0);
    }
}
Chilledrat
  • 2,593
  • 3
  • 28
  • 38

3 Answers3

0

I guess you should have to set component:

intent.setComponent(new ComponentName("com.package.address","com.package.address.MainActivity"));
Taras
  • 2,526
  • 3
  • 33
  • 63
0

You are calling an Activity that can VIEW the content of data you put in the Intent.

But if you do not have any installed applications that listens for a message of type: Intent.ACTION_VIEW, and accepts a Uri, then most probably the application will throw an exception.

From your description: service to open **another app**.
Well, it seems that "another app" can not be found.

Andy Res
  • 15,963
  • 5
  • 60
  • 96
0

Shouldn't that be (no abstract):

public class MainActivity extends Service
{
    @override
    public void onCreate()
    {
        super.onCreate();
        Toast.makeText(this, “Service created”,Toast.LENGTH_LONG).show();

        Uri anyConnectUri = Uri.parse(“anyconnect://connect/name= TestVPN”);
        Intent arg0 = new Intent(Intent.ACTION_VIEW, anyConnectUri);
        this.startActivity(arg0);
    }
}

Though you might want to change the name of the class to better reflect its use, as this is as services and not an activity.

Chilledrat
  • 2,593
  • 3
  • 28
  • 38