Update: Neither eclipse nor the code did cause these trouble. Genymotion did.
Maybe my approach is completely wrong, since no one else seems to have this problem - if so, i am open to try different ways rather then fix this problem:
I have the following setting.
A BroadcastReceiver is listening for installations of Apps. Whenever a new App is installed, I create a Notification, using a PendingIntent that is based on a normal Intent via
PendingIntent pIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
Before the PendingIntent is created, I put some extras in the normal Intent, that shall be passed to the Activity which is triggered, when the notification is clicked.
notificationIntent.putExtra("AppLabel", appLabel); // the installed App
notificationIntent.putStringArrayListExtra("Group", group); // the corresponding group
notificationIntent.putStringArrayListExtra("List", list); // the corresponding list
Now this works fine and the notification is displayed. Debugging I can see, that when pIntent is created, all extras are set correctly and passed.
However, when I try to read the extras in the opened Activity trouble starts. I already had to build a workaround, based on an answer here, to read the extras:
Bundle bundle = getIntent().getExtras();
for (String key : bundle.keySet()) {
Object value = bundle.get(key);
if (key.equals("Group")) {
group = (ArrayList<String>) value;
} ... }
This also worked for a time, but now i am completely lost. For some Reason, the ArrayList extras are empty [] - the appLabel is still set correctly.
Now the real trouble is, that I am not sure if this is code related, or an eclipse issue.
I observed, that after some deployments, the bundle.keySet() returned different keys then I had set in the putExtra call. I also encounter OutOfSync errors often when I search. Refreshing does help some times, regarding the names of the keys, but the values are lost still.
To anyone who has read this: many thanks! now - has somebody a clue, what is going on here? Does anyone know similar eclipse problems? Or is there an error in the code?
Any proposals for a different design are welcome as well. I'd be just glad, if I can exclude some error sources...
Thanks in advance
Update: Manifest Infos: The launched notification Activity is defined like:
<activity
android:theme="#style/Theme.AppCompat.CompactMenu.Dialog"
android:label="Notification Receiver"
android:excludeFromRecents="true">
</activity>
The MainActivity however has just a name and a label. Besides:
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="19" />
I just added a SystemOut at two points: One when the intent is created by the BCR, one when it is read by the Activity.
BroadcastReceiver.getExtras.keyset returns [a,b,c,d]
Activity.getExtras.keyset returns the keys [x,y,z]
Searching in all Projects and all Workspace, x,y,z are nowhere to be found... They were used in a previous version of some days ago, so it seems eclipse stored some invalid old data?
Well, looks like all the technical stuff and all the outOfSync was nasty, but in the end not relevant.
It just covered a very trivial mistake. The answere can be found here:
Incorrect extras received with all intents but the first one
At least for the current implementation, this looks like solving the problems - except for the sync issues of course but that has not occured again.
Related
I am a bit confused,
it seems that my Service does not print logs,
the service starts regularly (I can debug it), I see all other logs,
but from the service no logs.
Please what am I missing here?
#Override
protected void onHandleIntent(Intent intent) {
Log.e("TAG","Downlaoding devices list");//This should log something!
Chances are your IntentService is not getting called. try using the whole package name of the IntentService. I've seen this somewhere I'll post a link if I find it.
Something like this...
Intent intent = new Intent(this/*Context*/,com.myapp.MyIntentService.class);
//as opposed to
// new Intent(this, MyIntentService.class);
startService(intent);
Edit: I found the link. intentService : why my onHandleIntent is never called?
In Android Studio Logcat.
Before running your code,
1) Select No Filters instead of Show selected applications
2) In the search box, type in your tag.
3) Now Run your code and all your logs will be displayed.
Note: It won't work if you enter your tag after running your code.
My solution was selecting "No filters" in logcat spinner instead of "Show only selected application". Then you can search for TAG or whatever you know it should be shown.
In my case which is Himax M2 Y12 phone, has a peculiarity in that my TAG SensorService is blocked for unknown reason.
I changed the TAG to GeoSensorService and now the logcat is showing.
My guess is they reserve the TAG for internal purposes, but I'd argue they shouldn't use such an innocent naming (they could've prefixed reserved TAGs with __ or something).
I have my project classes organized in multiple src folders, which have been working just fine until I changed the switch between activities, now incorporating passing of strings to the following activity. I think the problem is related to the class path.
Bundle bundle = new Bundle();
bundle.putString("email", userEmail);
Intent intent = new Intent(MainActivity.this,
com.fm.mondev.MeanSelection.class);
intent.putExtras(bundle);
startActivity(intent);
[EDIT] I realized the problem is not entirely related to the path of the Classes, even though I currently have MeanSelection.class instead of com.fm.mondev.MeanSelection.class. In fact, the problema seems to be related to the bundle. It works when I use it between the Login and Main activities, but not for activities subsequent to the Main one. I have also tried the alternate approach shown below. I have the subsequent activities edited accordingly.
Intent intent = new Intent(MainActivity.this,
MeanSelection.class);
intent.putExtra("email", userEmail);
startActivity(intent);
I have looked at my logcat but I can not detect anything useful. I know this works if I comment the putExtra(s) line.
[ANSWER] After seeking through every error line of the logcat and reading your answers, I realized there was a problem with one of the variables written via Log.d. So, the solution was to erase those lines, since they were there just to verify if the variables were rightly picked from the previous activities via the bundle. My conclusion is: from now on, I will not Log the strings passed from one activity to another. I'm not sure if this is really an issue with Android or just one of those things that comes with no feasible explanation, which we all know so well, but as soon as I erased those lines, I had my app up and running.
The app crashes when it should open the second activity. It's the following error that makes me believe this is related to the path: "E/AndroidRuntime(7115): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fm/com.fm.mondev.MeanSelection}: java.lang.NullPointerException: println needs a message"
println needs a message has NOTHING to do with activity anything. Read your logcat!
I get this error when I try to Log a null value, i.e.
String foo = emptyBundle.getString("barValue");
Log.d(TAG, foo) // error, Log output functions cannot output null values.
Log.d(TAG, "barValue: " + barValue); // outputs "barValue: null"
Make sure whatever you're Logging or System.out.printlning has a value.
If your sending just one string, you shouldn't have to use Bundle.
Intent intent = new Intent(MainActivity.this, com.fm.mondev.MeanSelection.class);
intent.putExtra("com.fm.MainActivity.userEmail", userEmail);
startActivity(intent);
Should work fine. I don't really know if that solves your issue, because you never stated what the error message is.
According to the exception you get E/AndroidRuntime(7115): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fm/com.fm.mondev.MeanSelection}: java.lang.NullPointerException: println needs a message you are getting a NPE in some logging code in your com.fm.mondev.MeanSelection activity.
For instance, check this: NullPointerException : println needs a message in android
actually, you are gettin erro about:
java.lang.NullPointerException: println needs a message
I think you are passing somethin null to println method
hi
After creating intents for month now i suddenly
hit the wall when in my Notification PendingIntent, i did this:
Intent intent = new Intent(getApplicationContext(), SendFileService.class);
intent.putExtra("uuid", "123-456-34");
The SendFileService is an IntentService.
To my surprise in the IntentService onHandleIntent the extras.getString("uuid");
was null.
what can possible be the reason .
I even added an action to test but still the same.
Im clearly did something wrong or missing some knowledge about this.
Any ide?
From the docs
The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".
I would like to launch an app the user selects from within my application. However, I'm not sure how I'd go about doing this. I've tried this:
Intent intent = new Intent();
intent.setAction(Contacts.Intents.SHOW_OR_CREATE_CONTACT);
startActivity(intent);
But this seems to throw an error and force close my application. I also tried adding:
<action android:name="Contacts.Intents.SHOW_OR_CREATE_CONTACT"/>
in the AndroidManifest file, but to no avail.
A look at Logcat shows that it's an "IOexception - no such file or directory". A couple of questions arise from this. I read through the Android docs and noticed that the Contact.Intents class is deprecated. However, it's successor, ContactContracts is aimed at API level 5 whereas I'm targeting API level 3. Could this be the problem? Also, I've hardcoded this application into the code. Is there a way to retrieve the intents of any application the user selects so that they can be launched?
You need to pass extra information into the intent to tell Android what you want to show or create. Otherwise Android doesn't know what activity to start and (presumably in your case) throws an ActivityNotFoundException.
For a contact, you use the generic Intent.ACTION_INSERT_OR_EDIT then use the MIME type of an individual contact (Contacts.People.CONTENT_ITEM_TYPE).
For example:
Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
intent.setType(People.CONTENT_ITEM_TYPE);
intent.putExtra(Contacts.Intents.Insert.PHONE, "+1234567890");
intent.putExtra(Contacts.Intents.Insert.PHONE_TYPE, Contacts.PhonesColumns.TYPE_MOBILE);
That will bring up the contacts app, prompting you to select an existing contact to add the phone number to, or to create a new contact.
You don't need to add anything special to your manifest to start external activities. Only if you were to directly manipulate the contacts ContentProvider would you need to add the appropriate CONTACT permissions to your manifest.
I use this code for that purpose:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.Settings");
startActivity(intent);
This will launch the Settings app, you can use these also:
intent.setClassName("com.android.music", "com.android.music.MediaPlaybackActivityStarter");
intent.setClassName("com.android.contacts", "com.android.contacts.DialtactsContactsEntryActivity");
intent.setClassName("com.android.contacts", "com.android.contacts.DialtactsActivity");
The first starts the default music app, the second the contacts, and the third the dialer.
Hope this helps.
You need to pass in valid arguments to the apps you start. A lot of apps expect the data URI and / or certain extras to be valid.
Please try the following code:
Intent intent = new Intent(Contacts.Intents.SHOW_OR_CREATE_CONTACT);
this.startActivity(intent);
(sorry if there is something wrong on the syntax, I dont have android in this computer)
And remove the action from the manifest. that is not needed.
The action method is used for something else.
For more info, please look at the android site: http://developer.android.com/reference/android/content/Intent.html
Daniel
The activity you are calling should appear not only in the Manifest for its own package, but in the Manifest for the CALLING package, too.
Posted: Mon Nov 30, 2009 5:08 pm Post subject: Simple Problem With Intent Extras
Hello,
I'm working on an app widget for the home screen. I'm trying to make it so when a user taps on the widget it changes the data being displayed in the widget. However, I'm also allowing multiple instances of widgets open with different data. So in order to tell my method which widget to update, I'm adding an extra to the intent that is launched to change the data.
Here's the intent I have:
Java:
Intent changeData = new Intent("com.tonycosentini.mintdroid.CHANGE_DATA");
changeData.putExtra("widget_id", currentWidgetId);
PendingIntent changeDataPendingIntent = PendingIntent.getBroadcast(this, 0, changeData, 0);
//This will return the correct value, but if I call it in my onreceive() method it won't.
Log.v(TAG, "stored id is: " + changeData.getIntExtra("widget", 0);
This correctly stores the widget id, but when the change data method is called, the widget id that is read from the intent is the first widget instance. That is, there is is a for loop that generates all of the widgets and no matter what widget you tap, the widget id that is recieved is always the first widget id in the first widget.
Anyone have an idea on how to solve this? Hopefully I didn't word it too poorly.
Thanks for reading,
Tony
This is a known issue with PendingIntents; when Android compares PendingIntents it does not compare Intent extras, so you can't schedule the same basic Intent multiple times with only different extras. Right now, you can only solve this by making the Intent unique in some way other than extras, such as adding extra information to the Intent data.
There's a little bit of discussion of this on the Google Android Group: http://groups.google.com/group/android-developers/browse_thread/thread/81100da6ddb21136