我想简单地从我的 AlarmManager Activity 调用 BroadClass Activity 中定义的一个函数。为此,我制作了一个广播接收器,我从 Alarmmanager Activity 触发它,但我没有得到任何回应
AlarmManager 活动(从这里触发广播)
package com.mainActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class AlarmManagerActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = new Intent(AlarmManagerActivity.this,BroadClass.class);
intent.setAction("BROADCAST_ACTION");
sendBroadcast(intent);
}
}
我定义了广播接收器的 BroadClass 活动
package com.mainActivity;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.Toast;
public class BroadClass extends Activity {
public BroadcastReceiver broadCast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
Toast.makeText(BroadClass.this, "SDK Manager Activity", Toast.LENGTH_SHORT).show();
myFunction(); //which i want to call
}
},new IntentFilter("BROADCAST_ACTION"));
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
IntentFilter filter = new IntentFilter();
filter.addAction("BROADCAST_ACTION");
registerReceiver(broadCast, filter);
super.onResume();
}
public void myFunction(){
//mycode here
}
请帮助我..提前谢谢