basic Activity starting - java

I'm having some problems here with basic Activity starting
I've tried to use the method below:
private void startAC() {
Intent i = new Intent(this, WordSendingActivity.class);
startActivity(i);
}
And while debugging I got some "Source not found" errors which claim that the source attachment does not contain the source for the file: Instrumentation.class, InvocationTargetException.class, Binder.class (in this order)
I got these different class names by trying Run->Step Return
What am I doing wrong here? I just want to preform a basic activity start, how would you do it better?
took me hours to give up my pride and come here :)
I hope my question is clear enough...

It looks like you might be attempting to "Step Return" into built-in classes. Android classes don't have sources available for debugging. They are binary-only classes in the respective android.jar.
The code for starting the activity looks fine. Are you sure you added WordSendingActivity to the AndroidManifest.xml ?

Related

FLAG_ACTIVITY_NEW_TASK error integrating android native library in react native

I'm trying to integrate a native payment library in a react native application.
The library requires an view setup like this to process the pay result.
The library raises next error
Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
I don't know if my configuration is wrong, the native library demo application works fine. :(
The pay response intent tries load the activity but apparently it can't find it.
Update
The library function that fails is:
String appId = context.getPackageName() + "." + callbackSchema;
Intent intent = new Intent(appId);
intent.putExtra(ConstantUtil.RETURNED_JSON_KEY,json);
context.startActivity(intent); // <- this call raises the error
Update
Finally I made it work. I was passing context like that:
getReactApplicationContext()
I solved it passing context like that:
getCurrentActivity()
In debug, I got this values:
but the error still raising :(
Any idea?
Finally I made it work. I was passing context like that:
getReactApplicationContext()
I solved it passing context like that:
getCurrentActivity()

What causes the LoginActivity to run for the first time in the Socket.io android application example by nkzawa?

I have been trying to fully understand nkzawa's android example on github for socket.io
Relative link:
https://github.com/nkzawa/socket.io-android-chat/tree/master/app/src/main/java/com/github/nkzawa/socketio/androidchat
(AndoridManifest.xml is in the "main" folder)
I have been told that android decides which activity to run first from a tag inside AndroidManifest.xml that would have < action ... .MAIN and < category ... .LAUNCHER inside the activity. When I look at AndroidManifest.xml I see the aforementioned tags inside of the MainActivity declaration. Great! So MainActivity must be the first to run. Now, when I look at MainActivity.java I see an onCreate() method that just sets the content view with not much else to be seen.... So how does the LoginActivity start?
I have setup the server side of things without an issue and I can compile and run the example, connect to my server and all that... I just don't understand how the onCreate() method is first called for the LoginActivity.
There is definitely something I am missing. The LoginActivity must be started somewhere else besides AndroidMainifest.xml or MainActivity.java..
If anyone could point me in the right direction even it would be great! Thanks so much.
Alright I think I got it.
1. App starts at MainActivity.onCreate()
2. Sets content view with: setContentView(R.layout.activity_main)
3. Activity_main.xml opens a fragment that uses class MainFragment
4. MainFragment.onCreate() does some work then calls startSignIn()
5. startSignIn() calls startActivityForResult(intent, REQUEST_LOGIN) with the intent as the LoginActivity!
Now the LoginActivity has begun :)

DisplayMessageActivity cannot be resolved to a type-Building first android App

Hi I have just began working on the first android application on developer.android.com.
well to start with I got to learn many error origins and their solutions from S.O. , but i have been trying to figure out this statement
"DisplayMessageActivity cannot be resolved to a type" while we have to set an Intent for button onclick function. It shows this error in the line where the code line is:
Intent intent = new Intent (this, DisplayMessageActivity.class);
here is the java file:
MainActivity.java
}
/**called when the user clicks the send button*/
public void sendMessage(View view) {
Intent intent = new Intent (this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById (R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity (intent);
}
}
I tried a lot find which class do I need to import now, and searched but no avail.
may be I am a beginner is what I miss here.
Well, I think it's too late to answer and probably you figured out already.
However, just in case I'd like to put some more explanation.
Probably their "Starting Another Activity" section of Buidling Your First App" was revised after you posted your question, but I found that the user-defined "DisplayMessageActivity" is defined several lines below where you were guided to write code to create Intent and thus refer to DisplayMessageActivity.
At "Create Second Activity" section, the DisplayMessageActivity is created.
Well, Google's pedagogy style is not good, and I found out that their framework design ( and thus naming ) is not good and doesn't reveal what they are.
But.. if you choose Android platform to develop for, what can you do other than endure that. Good luck with that.
In that tutorial of developing first app, they create DisplayMessageActivity.java later part of tutorial. Please read the complete tutorial. The documentation have been corrected to indicate the same when using IDEs. You can visit here :
Note: The reference to DisplayMessageActivity will raise an error if you’re using an IDE such as Eclipse because the class doesn’t exist yet. Ignore the error for now; you’ll create the class soon.
http://developer.android.com/training/basics/firstapp/starting-activity.html#BuildIntent
DisplayMessageActivity is not a class predifined by android packages, so you should create it as ordinary java class and call from yours, here, MainActivity. Sure it doesn't require to be named as in the tutorial
You can create the display message activity class yourself by adding this code anywhere
public class DisplayMessageActivity {
}

Puzzling java.lang.NullPointerException in Android App

I'm currently working on an Android App and, almost every time I use it, I get a an error. Most of the time it doesn't crash the app, but it is still frustrating that I'm seeing this error. I thought I did a check for it, but I could be wrong. Thanks for the help! The relevant code is below. (It's relevant because the line outside the if statement is throwing the NullPointerException.)
Activity activity;
if(activity == null)
{
activity = new Activity();
}
Intent intent = new Intent(activity, Service.class);
You don't usually instantiate the Activity class in this manner. Please see the documentation on the Android Activity class here:
http://developer.android.com/reference/android/app/Activity.html
You should post some more of the surrounding code, but your problem is that creating new Intent requires a valid Context. Usually you create an Intent within an Activity (or Service or BroadcastReceiver) class so you can just do something like:
Intent intent = new Intent(this, Service.class);
Occasionally you'll create it somewhere else and pass it that valid Context, but you should pretty much never create an Activity by calling the constructor directly. There's a lot of other initialization necessary to make it useful.
As postet previously there is more to initiate for an activity than calling the constructor. Probably you get a null pointer exception deep within the Intent Constructer where it is trying to get some of the Activityinformation usually provided.
If you really want to create a Service, heres a link for starting a Service, but you should really read the whole article and probably some more of the activity lifecycle ressources.
http://developer.android.com/guide/topics/fundamentals/services.html#StartingAService

Why do I get "Unable to start service Intent"?

I'm trying get some licensing code from AndroidPit.com working, but I get "Unable to start service Intent". Basically my code looks like this:
Intent licenseIntent = new Intent("de.androidpit.app.services.ILicenseService");
if (mContext.bindService(licenseIntent, this, Context.BIND_AUTO_CREATE))
{
// success
}
else
{
// failure (I get this all the time(
}
I tried passing ILicenseService class explicitly:
Intent licenseIntent = new Intent(mContext, de.androidpit.app.services.ILicenseService.class);
but I still get the same problem.
I managed to get Android Market LVL library working which uses identical code, so I don't really understand why it fails to find "de.androidpit.app.services.ILicenseService", but manages to find "com.android.vending.licensing.ILicensingService".
Most of the answers I found here say that you need to append stuff to your AndroidManifest.xml, but you don't anything for "com.android.vending.licensing.ILicensingService" to work, so I guess I shouldn't need anything "de.androidpit.app.services.ILicenseService" (they both derive from android.os.IInterface).
Thanks in advance.
Most of the answers I found here say that you need to append stuff to your AndroidManifest.xml
Those answers are correct.
but you don't anything for "com.android.vending.licensing.ILicensingService" to work
That is because com.android.vending.licensing.ILicensingService is a remote service, one that is not in your project, but rather in the firmware of the device.
so I guess I shouldn't need anything "de.androidpit.app.services.ILicenseService" (they both derive from android.os.IInterface).
That is flawed reasoning. By your argument, java.util.HashMap does not go in the manifest, and both java.util.HashMap and any implementation of Activity all derive from Object, so therefore you do not need to put your activities in the manifest. If you try this, you will quickly discover that your activities no longer work.
If it is a component (activity, service, content provider, or some implementations of BroadcastReceiver), and the implementation of the component is in your project (directly, via a JAR, via a library project, etc.), you must have an entry in the manifest for it.
Wherever you got the service from should provide you with instructions for adding the service to your manifest, and they should also supply you with instructions for creating the Intent used to bind to it. If they do not provide this documentation, perhaps you should reconsider your use of this product.
The solution in my case was to start a server part on my phone (AppCenter from AndroidPit.com in this case). No entries in AndroidManifest are necessary for the client application.

Categories

Resources