this question may seem kinda broad but i'm sure once you've read up, the context will become clear.
I need to write a class that doesn't extend activity but i want it to be able to run onNewIntent Method.
The reason for this is because the class doesn't really have or need an interface or connect to a UI. I just need it to sniff for some intents in the background. I can't get the onNewIntent part to work just yet.
Here is what i mean.
public class MyClass {
private PendingIntent mPendingIntent;
private IntentFilter[] mFilters;
public MyClass(){
this.activity = activity;
doAction();
}
public void doAction(){
mPendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, new Intent(activity.getApplicationContext(),getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
mFilters = new IntentFilter[]{
new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED),
new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED),
new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED)};
}
//Now i want to do some action when there is a new intent but since it doesn't extend activity, this don't work. Extending activity will mean using onCreate and all that other good stuff which i don't want
@Override
public void onNewIntent(Intent intent) {
Toast.makeText(activity.getApplicationContext(), "Got to intent", Toast.LENGTH_SHORT).show();
super.onNewIntent(intent);
doStuffWithIntent(intent);
//This block doesn't work. I'm looking for alternative to get working.
}
}
Since the class doesn't need an interface, i see no reason why it should extend activity. But for what i want done to work properly, i need to check for new intent.
Would like to know if there is a workaround for a non activity class to listen for new intent.