Setting up a new project

This is a step-by-step tutorial for getting started connecting users with a new Activity. In case of problems the library will print (hopefully useful) logs to the console which you can capture with 'adb logcat'.

  1. Download and extract it

  2. Create a new Android project in Eclipse

  3. Include flock.jar into the project (screenshots):

    • Right click on your project in the Package Explorer and select "Properties"
    • Choose "Java Build Path", select the tab "Libraries", click on "Add External JARs"
    • Select flock.jar from the extracted sdk

  4. Enable inline documentation for Eclipse (useful for syntax recommendations and hovering over methods):

    • Expand flock.jar in the "Libraries" tab of step 3
    • Double click on "Javadoc location" and point to the directory "javadoc" from the extracted sdk

  5. Add your developer-id to AndroidManifest.xml, just before </application>

    <meta-data android:name="FLOCK_DEVELOPER_ID" android:value="your-developer-id" />

  6. Add the background-service to AndroidManifest.xml, just before </application>. If the project's package name is com.example.dice, the tag would be this:
    <service android:name="com.flockengine.BackgroundService">
            <action android:name="com.mycompany.mygame.BackgroundService" />
  7. Add permission INTERNET to AndroidManifest.xml, just before </manifest>:
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>

  8. In, extend FlockActivity instead of Activity, and to receive events from the engine add an FlockEventCallback at onCreate()
    public class YourActivity extends FlockActivity implements FlockEventCallback {
        public void onCreate(Bundle savedInstanceState) {
        public void onFlockEvent(FlockEvent event, int sender_id, String msg) {
            Log.v("", "new event: " + event + ", sender=" + sender_id + ", msg=" + msg);
            switch (event) {
            case SESSION_STARTS:
                Toast.makeText(this, "Game Starts", Toast.LENGTH_SHORT).show();;
                startActivity(new Intent(YourActivity.this, Game.class));

That's the basic setup! Now you can connect authenticate users, configure the engine and connect to the servers. You will need to start multiple emulators for testing.

Have a look at the examples to see how it works in action!

See also