Android初始化Parse对象时,如何获取ApplicationID与Server地址?
Hey there! Let's sort out the confusion around filling in applicationId and server values when initializing Parse on your Android app, especially since you're running Parse Server on Windows.
1. Understanding the Parse Application ID
Your current code uses "com.example.anshuman.parse_1" as the applicationId — but that's your Android app's package name, not the Parse Application ID. This value is something you set yourself when configuring your Parse Server. Here's how to find it:
- If you start Parse Server via command line, look for the
--appIdflag in your startup command. For example:
The string afterparse-server --appId "myCustomParseAppId" --masterKey "mySecureMasterKey" --databaseURI mongodb://localhost:27017/dev--appId(like"myCustomParseAppId") is what you need to put in theapplicationId()method. - If you use a configuration file (e.g.,
config.json), open the file and locate theappIdfield. It’ll look like this:
Copy the value of{ "appId": "myCustomParseAppId", "masterKey": "mySecureMasterKey", "databaseURI": "mongodb://localhost:27017/dev", "serverURL": "http://localhost:1337/parse" }appIdinto your Android code.
2. Fixing the Server URL
Your current server URL (http://18.220.188.73:4040) is missing a critical suffix: /parse. Parse Server uses this path as its default API endpoint, so omitting it will cause your Android app to fail when making requests.
Here’s how to get the correct server URL:
- If testing on an Android emulator with Parse Server running locally on Windows: Use
http://10.0.2.2:4040/parse(the emulator maps10.0.2.2to your Windows machine’slocalhost). - If accessing a public Parse Server (like the IP you used): Use
http://18.220.188.73:4040/parse— just add the/parsesuffix. Also, make sure:- Your Windows firewall allows inbound connections on port 4040.
- If your Windows machine is behind a router, you’ve set up port forwarding for port 4040 to your machine’s local IP.
Corrected Initialization Code Example
Using sample values (replace them with your actual Parse Server config):
Parse.initialize(new Parse.Configuration.Builder(this) .applicationId("myCustomParseAppId") // Your Parse Server's appId .server("http://10.0.2.2:4040/parse") // Local emulator URL, or public URL with /parse .build());
Quick Checks to Ensure It Works
- Verify your Parse Server is running and listening on the port you specified (4040 in your case).
- If using a public IP, test the server URL in a browser first — you should see a Parse Server welcome page at
http://18.220.188.73:4040/parse.
内容的提问来源于stack exchange,提问作者anshuman thakur

