2

I am trying to use the Parse.com sdk and I can't get my Parse codes to initialize. I don't know where to put it and I need help because I can't tell if I need to put it in my main or if I need to put it in somewhere else.

This is a few blocks of code I have put in different classes

I created this with the sample

package com.example.musicdroid;
import com.parse.Parse;
import com.parse.ParseACL; 
import com.parse.ParseUser;
import android.app.Application;

public class ParseApplication extends Application {

@Override
public void onCreate() {
    super.onCreate();

    // Add your initialization code here
    Parse.initialize(this, "XXX", "XXX");

    ParseUser.enableAutomaticUser();
    ParseACL defaultACL = new ParseACL();


    ParseACL.setDefaultACL(defaultACL, true);
}

}

This is where I had it originally

import com.parse.Parse;
import com.parse.ParseAnalytics;
import com.parse.ParseInstallation;
import com.parse.PushService;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Main extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String[] choices = { "Rock", "Metal", "Rap", "My Favorites" };
    setListAdapter(new ArrayAdapter<String>(this, R.layout.main,
            R.id.music, choices));
}

protected void onListItemClick(ListView l, View v, int position, long id) {
    switch (position) {
    case 0:
        try {
            startActivity(new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse("spotify:user:warnermusicus:playlist:3DRD3GUpQSjK2rryIRVOPS")));
        } catch (ActivityNotFoundException e) {
            final Intent intent = new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse("https://play.google.com/store/apps/details?id=com.spotify.mobile.android.ui"));
            startActivity(intent);
        }
        break;
    case 1:
        try {
            startActivity(new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse("spotify:user:warnermusicus:playlist:6iIDHF5tBqzS6uZjMEzBdQ")));
        } catch (ActivityNotFoundException e) {
            final Intent intent = new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse("https://play.google.com/store/apps/details?id=com.spotify.mobile.android.ui"));
            startActivity(intent);
        }
        break;
    case 2:
        try {
            startActivity(new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse("spotify:user:digsterdeutschland:playlist:5pvJLjAhcKCHXGOb7pEbBZ")));
        } catch (ActivityNotFoundException e) {
            final Intent intent = new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse("https://play.google.com/store/apps/details?id=com.spotify.mobile.android.ui"));
            startActivity(intent);
        }
        break;
    case 3:
        try {
            startActivity(new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse("spotify:user:digsterdeutschland:playlist:1hYWCuFv5Eav9yIZXHwnpd")));
        } catch (ActivityNotFoundException e) {
            final Intent intent = new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse("https://play.google.com/store/apps/details?id=com.spotify.mobile.android.ui"));
            startActivity(intent);
        }
        break;
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

Another place I had it. This is the Main Menu

package com.example.musicdroid;
import com.parse.Parse;
import com.parse.ParseAnalytics;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

 public class MainMenu extends ListActivity {
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String[] choices = { "Main", "Bios", "Artist Search", "How To Use" };
    setListAdapter(new ArrayAdapter<String>(this, R.layout.menu, R.id.Menu,
            choices));
}

protected void onListItemClick(ListView l, View v, int position, long id) {
    switch (position) {
    case 0:
        startActivity(new Intent(MainMenu.this, Main.class));
        break;
    case 1:
        startActivity(new Intent(MainMenu.this, Bios.class));
        break;
    case 2:
        startActivity(new Intent(MainMenu.this, Search.class));
        break;
    case 3:
        startActivity(new Intent(MainMenu.this, How.class));
        break;
    }
}
}

Manifest Code

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.musicdroid"
android:versionCode="1"
android:versionName="1.0" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<permission
    android:name="com.example.musicdroid.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.example.musicdroid.permission.C2D_MESSAGE" />

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/fiery_music_symbol"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Holo" >
    <activity
        android:name="com.example.musicdroid.Main"
        android:label="@string/app_name" >
    </activity>
    <activity android:name=".MainMenu" >
    </activity>
    <activity android:name=".Bios" >
    </activity>
    <activity android:name=".Search" >
    </activity>
    <activity android:name=".How" >
    </activity>
    <activity android:name=".LoginSignupActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Welcome" >
    </activity>

    <service android:name="com.parse.PushService" />

    <receiver android:name="com.parse.ParseBroadcastReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
    </receiver>
    <receiver
        android:name="com.parse.GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="com.example.musicdroid" />
        </intent-filter>
    </receiver>
</application>

</manifest>
2
  • FYI parse is going to shutdown in nearly 6 months time Commented Jun 3, 2016 at 11:06
  • True, but you can host your own server. Commented Jun 13, 2016 at 11:48

5 Answers 5

3

Add Your class extending Application inside Manifest File

<application android:name="your packagename.ParseApplication" 

 android:icon="@drawable/icon"  

 android:label="@string/app_name">

I hope this helps..

Sign up to request clarification or add additional context in comments.

Comments

1

Just put it to your MainActivity.java to onCreate with all the statements, which you have in ParseApplication's class onCreate. Then you can remove this class (ParseApplication.java) It should work properly.

Hope it helps

Comments

0

You should always place the initialize call in the ACTIVITY's onCreate method, just after the setContentView call. Like this:

protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_name_here);

    Parse.initialize(this, "ApplicationKey", "ClientKey);
    // Rest of your code follows...
}

Once you have that line, you can then do any Parse transactions.

Comments

0

Say you can't have custom app class (Eg: Android Library)

You can use the following procedure

Call initialize like this:

if (ParseCheck.isParseInitialized())
  Parse.initialize(context, PARSE.AB4FUN_APP.APPLICATION_ID, PARSE.AB4FUN_APP.CLIENT_KEY);

Create a utility class like below (note the package)

package com.parse;

public class ParseCheck {
  public static boolean isParseInitialized(){
    return Parse.isInitialized();
  }
}

Comments

0
import android.app.Application; 
import com.parse.Parse; 

public class MyApp extends Application { 

    @Override public void onCreate() { 
        super.onCreate();

        Parse.initialize(this, ApplicationID, ClientKey);
    }
} 
Then, add the following to your <application> in AndroidManifest.xml:
name=".MyApp"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.