Discussion Forums  >  Uncategorized

Replies: 4    Views: 997

eJucomm
Aspiring developer
Profile
Posts: 73
Reg: Nov 22, 2010
McAllen
730
08/28/11 03:00 PM (14 years ago)

Add the following code to the onCreate() method. What does this mean???

Needing your help. I am copying some code and the directions are as follows: Add the following code to the onCreate() method. Does this mean that I put the code within the parenthesis or after both parenthesis. Feeling hoping as I learn a new skill!
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
08/29/11 10:36 AM (14 years ago)
copying some code - from another project? NO worries but hard to understand what you're up to. The onCreate() method runs when an Android intent is created. It's sort of like the default constructor used in all java classes. It looks like this: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ....paste you custom code here }
 
LoglineEngine
I hate code!
Profile
Posts: 65
Reg: Sep 24, 2011
LA
650
like
10/08/11 10:44 PM (14 years ago)
Hi David, I am using parse.com for push notifications. Also having trouble with this step: ------- Call Parse.initialize from your onCreate methods to set your application id and client key: public void onCreate() { Parse.initialize(this, customcode, customcode); } ---------- You will also have to add import statements: import com.parse.Parse; import com.parse.ParseObject; What is the name of the file that I copy and paste this code in? I don't know where onCreate methods are located. Thanks. Patrice
 
duzkerotzki
I hate code!
Profile
Posts: 1
Reg: Dec 06, 2011
Nuremberg
10
like
12/07/11 08:52 AM (14 years ago)
Hey, i searched the forum but this is the only thread i found. This is the exact same questions i have too. Where is the oncreate() method included? Which files do I have to open to get to the oncreate() method? Thank you very much
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
12/07/11 07:00 PM (14 years ago)
Ok...I'll try to make some sense of this. If you can't follow along, it's OK, it will make sense eventually. Really, it will. It all starts by getting your head around the idea of an Android Activities Lifecycle. After you read this post you could see this for more info about Android Activity lifecycles: http://developer.android.com/guide/topics/fundamentals/activities.html#Lifecycle Here's how it works: Every screen in your app is an Android Activity. When each screen loads, it goes through a series of steps. These steps are called methods. There are a series of methods that EVERY activity goes through. The developer may or may not ignore these steps but they happen none the less. The most common step is the onCreate step. This method occurs when the screen is first created by Android, this happens before you see anything. It doesn't take long long finish the onCreate method (if it does, a developer doesn't understand this process and needs to move their long-running code to another method!) When the other steps happen make sense after understanding that concept. And, the method names give you, the developer, clues as to when they happen. onCreate(), onResume(), onStop(), onPause(), onDestroy(), etc. If we can understand when these happen, we can put our code in the proper place. In this case, the instructions at parse.com (i have not seen these) say to put it in the onCreate method. Makes perfect sense. It also says you'll need to import some libraries. If you open any .java file in your android project you'll see where the libraries are imported at the top. The tough part for you guys is to figure out what Activity .java file to put your code in. Each screen in your app has it's own activity.java class file. The type of screen you're working with will determine what file to work with. And, the buzztouch version you're using (v1.4, v1.5, self-hosted) will also affect this. v1.4: Find the src/projectname/Screen_what type of screen .java file. Example: A Custom HTML / Text screen would be /src/project/Screen_customHTML.java v1.5: Find the src/projectname/Screen_what type of screen .java file. Example: A custom HTML / Text screen would be src/projectname/BT_screen_customHTML.java You'll see the onCreate method. Paste your code just above the last 'curly brace' in this method. Everything in between the opening curly brace and the closing curly brace runs.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.