Saturday, April 13, 2013

How to get result from an activity:
=====================================

The following program snippet depicts how we can get result from an activity in an android application.

To launch an activity:
===========================
    Intent pickIntent= new Intent(this,PickServerActivity.class);
    //To launch an activity use below command:
    startActivityForResult(pickIntent, REQUEST_CODE_PICK_SERVER);

within activity, how to set result:
====================================
  Intent intent = new Intent();
  // start intent
   if(bServerSelected)
   {   
      intent.putExtra(ServerIntents.EXTRA_SERVER_NAME, selectedServerName);
      setResult(RESULT_OK, intent);
    } else {
          setResult(RESULT_CANCELED, intent);
     }

To get result from an activity:
====================================

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_CODE_PICK_SERVER) {
            if (resultCode == RESULT_OK) {
                Bundle extras = data.getExtras();
                if (extras != null) {
                    mServerName = extras.getString(EXTRA_SERVER_NAME);
            //Display Selected server from the activity   
                }
           
            }
        }
    }
   

Labels: , , ,

Thursday, October 04, 2012

How to Launch an activity/application  in android from commandline:
=============================================

commands to launch an application in android:

adb shell am start -a android.intent.action.MAIN -n packageName/.mainActivityName

If I want to launch one application from commandline, what things I need to do:

1)From APK's AndroidManifest.xml,we can identify the main activity.Then we can use above command

2)Another easy way is launch an application using GUI/by clicking the application At the same time take logs using "adb logcat".

ActivityManager(1132): Starting activity: Intent { cmp=com.android.providers.subscribedfeeds/com.android.settings.ManageAccountsSettings }

ActivityManager(1132): Displayed activity  com.android.providers.subscribedfeeds/com.android.settings.ManageAccountsSettings :500 ms


 we can launch this activity from commandline as below:

 adb shell am start -a android.intent.action.MAIN -n 
com.android.providers.subscribedfeeds/com.android.settings.ManageAccountsSettings
 

Labels: , ,