+

After a good feedback for our Monotouch / iOS Tips and Tricks series I decided to start the same thing for Android. This means I try to provide solutions for some common pitfalls during the Android development of our amazing product Fusonic Event Guide.

Please be aware that we do not use Monodroid here, we just use the native way to code the APP, this means all sample code is written in java and our IDE is Eclipse.

In the first part we go after:

  1. "Could not execute method of the activity"
  2. My development phone does not get found by adb
  3. Useful Emulator commands
  4. Start Facebook-App via intent + mobile alternative

If you have problems with the AlarmManager and BroadcastReceiver you can read about this in our last blog entry here. There is also some sample code included.

What means "java.lang.IllegalStateException: Could not execute method of the activity"

After a hard time of refactoring and renaming I tried to run my app again to test that everything is fine. But something goes wrong... the app did not start up properly and a nasty exception shows up in the debug window.
Ok, no problem here are the common pitfalls:

  • Activity is not defined in AndroidManifest.xml
  • Misspelled activity name in the AndroidManifest.xml (case sensitive!)
  • Use full qualified packagename instead of the shortend name attribute (e.g. android:name=".yourActivity") in the activity node. Because if you rename an activity eclipse removes the  dot "." and this could cause an error.

Your development phone does not get found by adb / Eclipse

Common pitfalls:

1. Stupid question: Is your phone connected to your pc? A: If not plug it please via USB.

2. Is your phone in "USB debugging"-mode? It has to be! So enable the debugging mode in your phone settings. (Settings -> Applications -> Development -> USB debugging)

3. What if it displays something like this "???????????" in the ADB-Manager? Ok, at first this is a good sign, because you have successfully solved problem 1 and 2. To solve this kind of problem you have to restart your adb-server running on your pc.

in Eclipse:

  1. Goto the Device-View in the DDMS-Perspective
  2. Click on the triangle on the right of the "Screen Capture"-Button
  3. Now click "Reset adb" in the context menu
  4. Restart your emulator

if this does not help do this via console..

on Linux :

sudo /my/path/to/android-sdk-linux_86/platform-tools/adb kill-server
sudo /my/path/to/android-sdk-linux_86/platform-tools/adb start-server

Useful Emulator commands

  • Switch screen orientation: Ctrl + F11/F12
  • Toggle fullscreen mode: Alt + Enter
  • Toggle trackball mode: F6
  • Toggle cell network: F8
  • Toggle menu: F2
  • Back: Esc

Full emulator controlling:
http://developer.android.com/guide/developing/tools/emulator.html

How to start Facebook-App via intent

In our app we wanted to provide a direct way to start the users Facebook-App. But starting alone is not enough, we have to navigate the user to our customers wall. If you are familiar with the Android System and Activities you know that they can expose functionality to other Activities via Intents.

So you just have to know the "Facebook-URI-Scheme" to access the right Activity of the FB-App.

Caution:
The scheme changed in the last update of the Facebook-App. The new scheme is posted below! But you should always keep in mind that this could be changed again!

Sample code to start the Facebook-App and open the customers Fanpage via pageid:
String uri = "fb://page/" + yourFBpageId;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));

// Add try and catch because the scheme could be changed in an update!
// Another reason is that the Facebook-App is not installed
try {

   startActivity(intent);

} catch (ActivityNotFoundException ex) {

   // start web browser and the facebook mobile page as fallback
   String uriMobile = "http://touch.facebook.com/pages/x/" + yourFBpageId;
   Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uriMobile));
   startActivity(i);
}
The new Facebook scheme (not everything tested):
fb://root
fb://feed
fb://feed/{userID}
fb://profile
fb://profile/{userID}
fb://page/{id}
fb://group/{id}
fb://place/fw?pid={id}
fb://profile/{#user_id}/wall
fb://profile/{#user_id}/info
fb://profile/{#user_id}/photos
fb://profile/{#user_id}/mutualfriends
fb://profile/{#user_id}/friends
fb://profile/{#user_id}/fans
fb://search
fb://friends
fb://pages
fb://messaging
fb://messaging/{#user_id}
fb://online
fb://requests
fb://events
fb://places
fb://birthdays
fb://notes
fb://places
fb://groups
fb://notifications
fb://albums
fb://album/{%s}?owner={#%s}
fb://video/?href={href}

comments powered by Disqus