Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9029853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:20:43+00:00 2026-06-16T07:20:43+00:00

I am trying to implement Salesforce OAuth in Android Application. I have used Salesforce

  • 0

I am trying to implement Salesforce OAuth in Android Application.
I have used Salesforce Mobile SDK for implementing it. I have also added ‘SalesforceSDK-1.0.1.jar’ in my project.

MainActivity.java

package com.android.templateapp;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.salesforce.androidsdk.app.ForceApp;
import com.salesforce.androidsdk.rest.ClientManager;
import com.salesforce.androidsdk.rest.ClientManager.LoginOptions;
import com.salesforce.androidsdk.rest.ClientManager.RestClientCallback;
import com.salesforce.androidsdk.rest.RestClient;


public class MainActivity extends Activity {

private RestClient client;
private ArrayAdapter<String> listAdapter;
private static String TAG = "TemplateApp";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.v(TAG," onCreate of Main Activity");
    // Setup view
    setContentView(R.layout.main);
}

@Override 
public void onResume() {
    Log.v(TAG," ******* default onResume of Main Activity");
        super.onResume();

        findViewById(R.id.root).setVisibility(View.INVISIBLE);
        Log.v(TAG," ******* default onResume - View.INVISIBLE");

        // Login options
        String accountType = ForceApp.APP.getAccountType();

        Log.v(TAG," ******* default onResume - accountType ::"+accountType);

        LoginOptions loginOptions = new LoginOptions(
                "https://login.salesforce.com/", // login host is chosen by user through the server picker 
                ForceApp.APP.getPasscodeHash(),
                getString(R.string.oauth_callback_url),
                getString(R.string.oauth_client_id),
                new String[] {"api"});
        Log.v(TAG," ******* default onResume - loginOptions ::"+loginOptions);


        // Get a rest client
        new ClientManager(this, accountType, loginOptions).getRestClient(this, 
                       new RestClientCallback() {
            @Override
            public void authenticatedRestClient(RestClient client) {

                // Show everything
                findViewById(R.id.root).setVisibility(View.VISIBLE);

                //User is authenticated, insert Application logic here
            }
        });
    }


protected LoginOptions getLoginOptions() {
    Log.v(TAG," getLoginOptions of Main Activity");
    LoginOptions loginOptions = new LoginOptions(
            null, // login host is chosen by user through the server picker 
            ForceApp.APP.getPasscodeHash(),
            getString(R.string.oauth_callback_url),
            getString(R.string.oauth_client_id),
            new String[] {"api"});
    return loginOptions;
}

public void onResume(RestClient client) {
    Log.v(TAG," onResume of Main Activity");
    // Keeping reference to rest client
    this.client = client; 

    // Show everything
    findViewById(R.id.root).setVisibility(View.VISIBLE);
}

/**
 * Called when "Logout" button is clicked. 
 * 
 * @param v
 */
public void onLogoutClick(View v) {
    ForceApp.APP.logout(this);
}

/**
 * Called when "Clear" button is clicked. 
 * 
 * @param v
 */

public void onClearClick(View v) {
    listAdapter.clear();
}   

/**
 * Called when "Fetch Contacts" button is clicked
 * 
 * @param v
 * @throws UnsupportedEncodingException 
 */

public void onFetchContactsClick(View v) throws UnsupportedEncodingException {
    sendRequest("SELECT Name FROM Contact");
}

public void onFetchAccountsClick(View v) throws UnsupportedEncodingException {
    sendRequest("SELECT Name FROM Account");
}   

private void sendRequest(String soql) throws UnsupportedEncodingException {
    RestRequest restRequest = RestRequest.getRequestForQuery(getString(R.string.api_version), soql);

    client.sendAsync(restRequest, new AsyncRequestCallback() {
        @Override
        public void onSuccess(RestRequest request, RestResponse result) {
            try {
                listAdapter.clear();
                JSONArray records = result.asJSONObject().getJSONArray("records");
                for (int i = 0; i < records.length(); i++) {
                    listAdapter.add(records.getJSONObject(i).getString("Name"));
                }                   
            } catch (Exception e) {
                onError(e);
            }
        }

        @Override
        public void onError(Exception exception) {
            Toast.makeText(MainActivity.this,
                           MainActivity.this.getString(ForceApp.APP.getSalesforceR().stringGenericError(), exception.toString()),
                           Toast.LENGTH_LONG).show();
        }
    });
}

}

I am getting following errors in logcat:

12-18 17:47:04.696: E/Trace(1586): error opening trace file: No such file or directory (2)
12-18 17:47:05.256: V/TemplateApp(1586):  onCreate of Main Activity
12-18 17:47:05.526: V/TemplateApp(1586):  ******* default onResume of Main Activity
12-18 17:47:05.526: V/TemplateApp(1586):  ******* default onResume - View.INVISIBLE
12-18 17:47:05.536: D/AndroidRuntime(1586): Shutting down VM
12-18 17:47:05.536: W/dalvikvm(1586): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
12-18 17:47:05.546: E/AndroidRuntime(1586): FATAL EXCEPTION: main
12-18 17:47:05.546: E/AndroidRuntime(1586): java.lang.RuntimeException: Unable to resume activity {com.android.templateapp/com.android.templateapp.MainActivity}: java.lang.NullPointerException
12-18 17:47:05.546: E/AndroidRuntime(1586):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2575)
12-18 17:47:05.546: E/AndroidRuntime(1586):     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2603)
12-18 17:47:05.546: E/AndroidRuntime(1586):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2089)
12-18 17:47:05.546: E/AndroidRuntime(1586):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
12-18 17:47:05.546: E/AndroidRuntime(1586):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
12-18 17:47:05.546: E/AndroidRuntime(1586):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-18 17:47:05.546: E/AndroidRuntime(1586):     at android.os.Looper.loop(Looper.java:137)
12-18 17:47:05.546: E/AndroidRuntime(1586):     at android.app.ActivityThread.main(ActivityThread.java:4745)
12-18 17:47:05.546: E/AndroidRuntime(1586):     at java.lang.reflect.Method.invokeNative(Native Method)
12-18 17:47:05.546: E/AndroidRuntime(1586):     at java.lang.reflect.Method.invoke(Method.java:511)
12-18 17:47:05.546: E/AndroidRuntime(1586):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-18 17:47:05.546: E/AndroidRuntime(1586):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-18 17:47:05.546: E/AndroidRuntime(1586):     at dalvik.system.NativeStart.main(Native Method)
12-18 17:47:05.546: E/AndroidRuntime(1586): Caused by: java.lang.NullPointerException
12-18 17:47:05.546: E/AndroidRuntime(1586):     at com.salesforce.androidsdk.app.ForceApp.getAccountType(ForceApp.java:175)
12-18 17:47:05.546: E/AndroidRuntime(1586):     at com.android.templateapp.MainActivity.onResume(MainActivity.java:85)
12-18 17:47:05.546: E/AndroidRuntime(1586):     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1184)
12-18 17:47:05.546: E/AndroidRuntime(1586):     at android.app.Activity.performResume(Activity.java:5082)
12-18 17:47:05.546: E/AndroidRuntime(1586):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2565)
12-18 17:47:05.546: E/AndroidRuntime(1586):     ... 12 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:20:45+00:00Added an answer on June 16, 2026 at 7:20 am

    I’d imagine that you have not setup an application class that extends ForceApp and registered that in the AndroidManifest.xml file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to implement the following behavior on an iPad. I have a map-centric application
I am trying implement a photo gallery similar to facebook in Android. I was
Trying to implement what I thought was a simple concept. I have a user
I have this weird kind of error. I am trying implement basic Euclidean algorithm
When trying to implement a simple OpenGL application, I was surprised that while it
I'm new in mule ESB and I'm trying implement a simple application flow: <mule
Trying to implement import and export feature in my application.Exporting is just copying of
I'm trying implement a custom login page to use in my JSF 2.0 application.
Trying to implement a timer for my game that I'm making. I have a
Trying to implement a simple print in SL4. I have a DataGrid that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.