I am facing a problem that when the Time changes the TIME_TICK only called when the app is running. But i want to get it called even when app is running or not using broadcast receivers.
Main Activity
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(getApplicationContext(), "Checking", Toast.LENGTH_LONG).show();
}
}
MyBroadastReceivers
public class MyBroadastReceiversextends BroadcastReceiver
{
@Override
public void onReceive(Context arg0, Intent arg1) {
Toast.makeText(arg0, "Toast Receive", Toast.LENGTH_LONG).show();
}
}
Menifest File
<receiver android:name="com.example.serviceschecking.MyBroadastReceivers" android:enabled="true" android:exported="true">
<intent-filter >
<action android:name="android.intent.action.TIME_TICK"/>
</intent-filter>
</receiver>
As described in API You have to register this intent programmatically:
Broadcast Action: The current time has changed. Sent every minute. You can not receive this through components declared in manifests, only by explicitly registering for it with Context.registerReceiver().
You have to register it for example in Your mainActivity:
IntentFilter mTime = new IntentFilter(Intent.ACTION_TIME_TICK);
registerReceiver(YourReceiver, mTime);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With