So I am using BaseGameUtils to try and get Google Games to sign in. Now I have changed my activity, but I am getting some compile errors with setContentView() or anything else that uses the base activity. This is what it looks like,
Error image:
Unused Activity/Import:
Any advice anyone?
BaseGameActivity extends LoaderActivity. And, LoaderActivity extends Activity.
Therefore, If you already imported BaseGameActivity, you don't need to import android.app.Activity.
If you using Eclipse, just press [Ctrl + Shift + O] to remove useless imported files.
If you are using BaseGameActivity, you should override onSetContentView() instead of onCreate() and you can use this.setContentView() inside it.
Related
I moved the NavigationTabbedActivity from one project to another, but I'm getting this error:
setSupportActionBar method cannot be found.
I've tried replacing the import widget.toolbar with import android.support.v7.widget.Toolbar; but it doesn't solve the problem.
Actually it needs the class to extend Activity but in my case the class already extends CustomActivity which in turn extends the default AndroidActivity, I tried extending customActivity with AppCombatActivity but it didn't work either. Is this error because I copied the file? Where am i wrong?
Ok while copying the file i forgot to add appcompat in the manifest file. so add the AppCompatActivity in the manifest file ie)
compile 'com.android.support:appcompat-v7:22.+'
and extended the custom activity to AppCompatActivity , and resynced the project , that solved the problem , thanks for your suggestions :)
Based on the small amount of information that was given I will try and provide a answer.
First of, when you copy a file over to a new project the activity doesn't exist in yourManifest.xml so make sure you declare it in your manifest.
You would also have to copy the layout file from the previous project or change it in your new one.
The next thing is the old project name will still be at the top and needs to be changed to the new project name.
My best advice would be to remove all the imports at the top and import everything again to make sure all the classes and everything is imported correctly.
I just started playing around with android annotation.
I know that when I do #Eactivity, another ActivityName_ class is generated instead.
Now, in my code, i have ActivityName.this written somewhere. But when i change it into ActivityName_.this, my compiler starts to complain that it is not recognized. My question is how do I import the proper ActivityName_ ?
First of all, you do not have to change all the class names to the generated class name. In this case, writing ActivityName.this will work just fine. Actually you only have to use the generated class names for Activitys in two places:
in the manifest where you declare the Activity
in your intents, where you start an Activity (and you can use the generated Intent builder: ActivityName_.intent(this).start()
The generated classes will be available after you compile (make) the project. So please compile the classes first.
I've imported google drive quick start project and it's MainActivity contains these functions:
com.google.android.gms.drive.sample.quickstart.MainActivity.onActivityResult(int, int, Intent)
com.google.android.gms.drive.sample.quickstart.MainActivity.onConnected(Bundle)
com.google.android.gms.drive.sample.quickstart.MainActivity.onConnectionFailed(ConnectionResult)
com.google.android.gms.drive.sample.quickstart.MainActivity.onDisconnected()
com.google.android.gms.drive.sample.quickstart.MainActivity.onPause()
com.google.android.gms.drive.sample.quickstart.MainActivity.onResume()
How does it work without onCreate method?
First of all I think you mean Activity onCreate method, not Application onCreate as you mentioned in the title. It is not the same. com.google.android.gms.drive.sample.quickstart.MainActivity implements android Activity therefore it contains default implementation of onCreate().
From what I can tell, Eclipse only supports making "skeleton-code" for very few class extensions in Android (such as Activity). If I want to extend TextView, Fragment, etc. I have to start completely from scratch and provide my own skeleton code.
Is that true, or am I missing something simple in Eclipse that creates skeleton code for various class extensions?
If by skeleton code you mean overriding the methods in the super class, then try the following:
In the package explorer, right click on the class, go to the Source tab and select Override/Implement Methods.... This will give a list of the methods you can override and implement.
Alternatively, go to a new line in the class editor outside of an existing method and press control + space to bring up a list of methods you can override. This is faster when overriding only one or two methods.
There is no difference between Activity or TextView when creating a new class from the Eclipse wizard.
By default all methods that need to be implemented will be auto-generated (constructors, abstract methods, interfaces' methods)
Say you class extends TextView.
Eclipse will ask you to override certain required methods in your class.
If you want to override some additional methods.
Right Click on the class name TextView. Goto Source and select Override/Implement methods. Then select the methods you want to override in your own class.
I have copied an activity class from the internet : get user input
When I had the activity class inside the project, as a class file - it worked fine.
When I inserted the class +layout file into a different project (my dialogs.jar file) I could not start the activity.
The activity (TextEntryActivity) is under "com.xyz.dialogs"
My project is under "com.xyz.thisproject"
First I got the "activity class not found" error:
"AndroidRuntime(487): android.content.ActivityNotFoundException: Unable to find explicit activity class ..."
Then I read in an article that I should insert the startActivityForResult into a try/catch and I did.
The result is :
Activity is not shown
onActivityResult is fired without any action from the user
Notes:
I put the activity in both manifests (first only in jar,then in my project, then both)
I have another class (not activity!) in that JAR file and its working fine (a OK only dialog I build with dialog builder)
My questions are:
Is it at all possible to put an activity in an external library ?
Is it ok that that the layout file is in the jar (its only a textbox with two commands ok/cancel)
Where should I declare the activity (which manifest or both?)
How should I declare the activity (I saw samples with "ActivityName" and some other samples with ".ActivityName" where should I use what method...)
Thanks in advance
Guy
I have at least a workaround:
Make an Eclipse library project with your activity (there is an is-library property in the Android properties of an Android project) and make your second project use the library project. Here is more information on that topic: http://developer.android.com/guide/developing/projects/projects-eclipse.html
Then subclass your activity and declare the subclass in the manifest. This works around the package issue.