1

Topic: static PendingIntent not in the main flow, I can not think what to write instead of this

pblic static void SendSMS (String n, String t) {
PendingIntent sentPI = PendingIntent.getBroadcast (this, 0, new Intent ("SMS_SENT"), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast (this, 0, new Intent ("SMS_DELIVERED"), 0);
SmsManager sms = SmsManager.getDefault ();
sms.sendTextMessage (n, null, t, sentPI, deliveredPI);
Log.d (LOG, "Sent");
}

If static this does not roll. If I remove static whence I cause SendSMS I can not cause (it static)....
With a sound the same problem with this.

try {
Uri notify = RingtoneManager.getDefaultUri (RingtoneManager. TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone (this, notify);
r.play ();
} catch (Exception e) {
e.printStackTrace ();
}

I wind off all static, to an alarm clock. With it began... static

public static class Alarm extends BroadcastReceiver {

So on a circle. How to solve this problem?

2

Re: static PendingIntent not in the main flow, I can not think what to write instead of this

You need to receive an application context simply

3

Re: static PendingIntent not in the main flow, I can not think what to write instead of this

You declare the application

public class ApplicationController extends MultiDexApplication {
private static volatile ApplicationController sInstance;
@Override
public void onCreate () {
sInstance = this;
super.onCreate ();
}
public static ApplicationController getInstance () {
return sInstance;
}
}

You register in the manifesto
<application
android:name = ". ApplicationController"
...
And now in any place of application to you it is accessible Application Context as ApplicationController.getInstance ()

4

Re: static PendingIntent not in the main flow, I can not think what to write instead of this

JavaStudent wrote:

So on a circle. How to solve this problem?

At  the context is transferred:

public void onReceive (Context context, Intent intent) {

5

Re: static PendingIntent not in the main flow, I can not think what to write instead of this

wadman, again you rescue me. Thanks. I did not know that context it is possible to transfer...
Solved a problem, your method
In service I transfer in a problem together c context

public static class Alarm extends BroadcastReceiver {
@Override
public void onReceive (Context context, Intent intent)
{
onTask (context, intent.putExtra ("T", "SM"));
}
}

6

Re: static PendingIntent not in the main flow, I can not think what to write instead of this

Oleg Shishkin Thanks. While there is no time to try. I will return to this implementation later.
For me while word Instance - magic.