• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps cannot start a inner class service

dougDaG

Lurker
Oct 13, 2010
1
0
it seems that cannot nest a service class in a activity class...
to run the following code, i got the errormsg;
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate service inner.service.InnerService$Inner: java.lang.IllegalAccessException: access to class not allowed.....

Androidmanifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="inner.service"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".InnerService"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".InnerService.Inner"/>
</application>
</manifest>


InnerService.java:

public class InnerService extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Intent i = new Intent(InnerService.this, Inner.class);
startService(i);
}
});
}
public static final class Inner extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public void onCreate() {
super.onCreate();
Log.e("-->", "create service");
}

@Override
public void onDestroy() {
super.onDestroy();
Log.e("-->", "stop service");
}
}
}

Any help would be welcome
d&g
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones