17939

Where to place the parse.initialize()

I'm currently building an app with a small team on both iOS and Android, though right now I'm only focussing on Android. On their website tutorial they say the following line fairly early.

Before continuing, select your Parse app from the menu at the right. These steps are for your "NameAppHere" app.

Call Parse.initialize from the onCreate method of your Application class to set your application id and client key:

public void onCreate() { Parse.initialize(this, "XXXXXX", "XXXXXX"); }

They say I have to paste that bit of code in the onCreate method of the Application class, though there isn't an 'Application' class or Application.java. I already copied their .jar file into the project structure through one of the menu options Android studio gives me. I specified before this walkthrough that I already have an existing project, so I don't think that's the problem.

Answer1:

You have to create your own custom Application class by creating a class that extends Application and then override onCreate (just like you would any activity) and place that line in.

public class MyApplication extends Application { public void onCreate() { Parse.initialize(this, "XXXXXX", "XXXXXX"); } }

You also have to tell the manifest that you are using a custome application class. You can do this by, in your AndroidManifest.xml file, you will have to set the name element to the location of you new Application class:

<application android:name="com.packageName.example.MyApplication" android:label="@string/app_name" android:logo="@drawable/ic_launcher_no_text" >

Answer2:

You should create class and extend it to Application

public class ParseApplication extends Application { @Override public void onCreate() { Parse.initialize(this, "XXXXXX", "XXXXXX"); //...Rest of the Parse initializations. } }

Answer3:

It always exists, but if you want to modify it, you can extend the Application class.

There's a tutorial over here explaining how: http://www.devahead.com/blog/2011/06/extending-the-android-application-class-and-dealing-with-singleton/

The official Google Android docs on this topic can be found here.

Recommend

  • How to calculate the total of two fields for each item in the queryset
  • Distcp Mismatch in length of source
  • Class cannot be cast to ParseObject
  • Uncaught Error: Cannot find template script at ID 'qq-template'!
  • Emacs lua-mode issue: (void-function interactively-called-p)
  • Want to understand iframe breakout code
  • Run multiple queries from 1 SQL file showing result in multiple tables
  • Spring Cloud Microservice Architecture Confusion
  • Transactional Create with Validation in ServiceStack Redis Client
  • Xcode 4 NSLog Macro link in Xcode 3
  • Allowing both email and username for authentication
  • Handling un-mapped Rest path
  • Get one-time binding to work for ng-if
  • Why value captured by reference in lambda is broken? [duplicate]
  • PHP - How to update data to MySQL when click a radio button
  • C# - Serializing and deserializing static member
  • Sending data from AppleScript to FileMaker records
  • sending/ receiving email in Java
  • How do you troubleshoot character encoding problems?
  • Akka Routing: Reply's send to router ends up as dead letters
  • Cannot Parse HTML Data Using Android / JSOUP
  • How to include full .NET prerequisite for Wix Burn installer
  • How to set the response of a form post action to a iframe source?
  • JTable with a ScrollPane misbehaving
  • Why joiner is not used after Sequence generator or Update statergy
  • Java static initializers and reflection
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • Is it possible to post an object from jquery to bottle.py?
  • unknown Exception android
  • EntityFramework adding new object to nested object collection
  • Checking variable from a different class in C#
  • Django query for large number of relationships
  • Recursive/Hierarchical Query Using Postgres
  • reshape alternating columns in less time and using less memory
  • Observable and ngFor in Angular 2
  • failed to connect to specific WiFi in android programmatically
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app
  • How can I use threading to 'tick' a timer to be accessed by other threads?