Reputation: 51
After spending near a full week copying and pasting about every example online, I have come to realise that I just don't understand serviceIntent.
I understand the theory(I think), it's just it never works for me when I try. I have stripped my existing code, leaving only what's necessary to ask this question, using 'println' to demonstrate a working example or not. Could you guys tell me where I am going wrong. Thanks.
If it's important, I am only using AIDE. I have checked if AIDE has limitations in regards to intentservices but have found nothing to say not.
MAINACTIVITY.JAVA
package com.mycompany.rns;
imports are listed here...
public class MainActivity extends Activity {
public class MyService extends IntentService {
public MyService(){
super("MyService");
}
@Override
protected void onHandleIntent(Intent intent) {
system.out.println("At fucking last!");
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent k = new Intent(this,MyService.class);
startService(k);
}
}
MANIFEST.XML
</activity>
<service
android:name=".MyService"
android:enabled="true"
android:exported="false" />
</application>
Upvotes: 1
Views: 159
Reputation: 51
As Ahmed Ewiss has given a correct answer, but not created an answer that I can accept, using his advice, this is for everyone else as a simple template they can use...
MAINACTIVITY.JAVA
package com.mycompany.rns;
imports are listed here...
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent k = new Intent(this,MyService.class);
startService(k);
}
}
MYSERVICE.JAVA
package com.mycompany.rns;
imports are listed here...
public class MyService extends IntentService {
public MyService(){
super("MyService");
}
@Override
protected void onHandleIntent(Intent intent) {
system.out.println("At fucking last!");
}
}
MAIN.XML
</activity>
<service
android:name=".MyService"
android:enabled="true"
android:exported="false" />
</application>
The working solution was to seperate the MainActivity.java file from the Service.java file. class file.
Upvotes: 1