Monday, July 14, 2014

How to add new items in Android Apps

Posted here as a reminder on how to update my live addorid app.

1. Add button in Layout
2. Add as function to the corresponding activity
3. Turn on developers options in Android phone
4. Must turn on USB debugging to allow Eclipse to detect
5. Run

Tuesday, October 8, 2013

How to bullet-proof an intent via verification of existence of app to handle it ?

Here's a complete example that shows how to create an intent to view a map, verify that an app exists to handle the intent, then start it:
// Build the intent
Uri location = Uri.parse("geo:0,0?q=1600+Amphitheatre+Parkway,+Mountain+View,+California");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);
// Verify it resolves
PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(mapIntent, 0);
boolean isIntentSafe = activities.size() > 0;
  // Start an activity if it's safe
if (isIntentSafe) {
    startActivity(mapIntent);
}

Monday, October 7, 2013

How to convert hard-coded string into String Resource?

The fastest and time-saving way to convert all the hardcoded strings in your ADT project si as follows :-

1) Select the hardcoded string including the ""
2) Click Ctrl+1
3) Select Extract Android string
4) Click OK

Where to find XML files for editing in Eclipse ?

Simple, most of your XML files within your Android project are located in the Layout Folder under Res :-)

Sunday, October 6, 2013

How to call another activity from a Button ?

To call another activity from a button or a menu-like component, proceed as follows:

1. Calling XML file (activity_serve_motion.xml)
Add   android:onClick="ServeMotionStaggered"
where ServeMotionStaggered is the next activity XML

<Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="ServeMotionStaggered"
        android:text="Staggered" />

2. Add a method to call ServeMotionStaggeredActivity in Java file (ServeMotionActivity.java)

       public void ServeMotionStaggered(View view) {
     // Do something in response to button
Intent intent = new Intent(this, ServeMotionStaggeredActivity.class);
startActivity(intent);
}

3. Create ServeMotionStaggeredActivity as follows:-
a) Put your cursor at src
b) Right-click and select Others
c) Select Andorid Activity
d) Select Blank Activity
e) Change Activity name to ServeMotionStaggeredActivity
f) Click Finish

4. Run your apps

5. Click your button and the new Tab displaying 'Hello' shoudl display