Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TIME_TICK not called when minute changes

Tags:

java

android

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> 
like image 438
Zeeshan Ali Avatar asked May 13 '15 08:05

Zeeshan Ali


1 Answers

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);
like image 159
Opiatefuchs Avatar answered Oct 29 '22 11:10

Opiatefuchs