Using IntentService
Activity: StartService
onHandleIntent IntentService
package lmoroney.com.hogeactivity; import android.app.IntentService; public class DetectedActivitiesIntentService { protected statid final String TAG = "detection_is"; public DetectedActivitiesIntentService(){ // Use the TAG to name the worker thread. super(TAG); } }
Get ActivityRecognitionResult
Use .getProbableActivities() to get Array
create a new Intent to send results
Add activities to Intent
Use a LocalBroadcastManager
Editing the Main Activity
on the class declaration
implement onConnectionCallbacks
and onConnectionFailedLsitener
Within the Class
Implement onConnected
Implement onConnectionSuspended
Implement onConnectionFailed
public class MainActivity extends ActionBarActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public void onConnected(Bundle connectionHint){ } @Override public void onConnectionFailed(ConnectionResult result){ } }
The Receiver Class
class that extends BroadcastReceiver
works best as a nested class on MainActivity
Create ActivityDetectionBroadcastReciever
– make it nested
– extends BroadcastReceiver
– Override onReceive(Context, Intent
public class ActivityDetectionBroadcastReceiver extends BroadcastReceiver { protected static final String TAG = "receiver"; public void onReceiver(Context context, Intent intent){ } }