Android : What Intents Do I Use To Pass / Receive Variable To Another Class?
Feb 17, 2009What intents do I use to pass a variable to another class? And also which intent do I use to receive it?
View 3 RepliesWhat intents do I use to pass a variable to another class? And also which intent do I use to receive it?
View 3 RepliesI am trying to extend the "android.content.Intent" class by adding a private attribute of a custom class. My goal is to send complex objects from the main Activity to a background Service.
The extension itself is not a problem, the class gets compiled without any errors and the project runs. The only problem is that the BroadcastReceiver does not receive the modified Intent and the "onReceive" method gets never called.
It there any way to pass complex objects with the help of Intents?
I am pretty new to this but I was told I could get good help here. A friend and myself are playing around with creating Android apps (using ADT)
Here is how we are trying to make the program: in activity, user sets threshold values for the X and Y axis on accelerometer. When user hits button "Start", startService is invoked and starts TiltService.
TiltService is designed to run in the background always on the phone without user interaction. TiltService constantly compares the threshold with the accelerometer values and will vibrate if they are off.
My problem is I can't seem to get the putExtra() data correctly. I have overridden the onStartCommand in my service but I get the message "unreachable code" when I save the getExtras() to a bundle.
Here is the relevant code (I can post the whole thing, just do not want to clog up page) code...
I thought I understood the basic of how Intents could pass data, but I guess I don't. Is it obvious what I am missing?
I have a layout with dynamic content. It has a variable number of textviews. On each textview I have to attach an event, a click event. I have to pass to that event some kind of information to know what textview has been clicked exactly. How can I pass this kind of information or how is the android way to do it?
View 1 Replies View RelatedI am a complete newbie with tasker. I am trying to create a profile with which I wish to auto-send an sms to wish people, for example on their birthday. So birthdays, set from contact appear on my calendar as "personName. Birthday"
I am able to trigger an action reading "*Birthday" in calendar event. But how do I pass the personName from the trigger, that matched "*Birthday" to the action to use as contact (directly or by extracting number for that contact) and the enter in the message like: Happy Birthday personName!
I am working to set a countdown timer. I have successfully (borrowed) a number picker (spinner) and set up the dialog box for the user to set the time. This is in a class called timepickactivity and the variables are hour and mins (R.id.hour and R.id.mins). I want to call the set values (R.id.hour and R.id.mins) from the dialog (timepickeractivity) to the actual countdown class (countdown) but I can't figure out how to get the values.
View 4 Replies View RelatedI have tried to understand for the past 2 days what is the best approach to making the value from a variable sitting in activity A (in my case, the int position used in OnListItemClick / OnItemSelectedListener) available in another activity B (which of course sits in another class). There may be the option to write the result of the OnListItemClick int position into a small SQLite DB - but that seems to be total overkill.
Anybody could pls share the best approach with me?
I am trying to register a Broadcast Receiver to receive broadcast events for the package events. Following is the code and my receiver in the manifest file. The log statment never happens, but I can clearly see the same broadcast firing for "HomeLoaders" (the Launcher) debug statements.
public class IntentListener extends BroadcastReceiver {
@Override public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.i("INTENT LISTNER:", intent.getAction()); } }
<receiver android:name="IntentListener" android:enabled="true" android:exported="true">
<intent-filter> <data android:scheme="package"></data>
<action android:name="android.intent.action.PACKAGE_ADDED"></action>
<action android:name="android.intent.action.PACKAGE_ADDED"></action>
<action android:name="android.intent.action.PACKAGE_CHANGED"></action>
</intent-filter> </receiver>
I would like to setup a boolean called dFlag in the main.class of my program and reference it in another class.
I already have it setup to work locally just hitting a snag on how to do it.
Code:
public class Main extends Activity {
boolean dFlag; ///Debug flag, true=enabled | false=disabled
}
public class Other extends Activity {
if(dFLag = true) {
///Output debug message
}
}
Or is there an easier way to do what I want without having to re-invent the wheel so to speak?
I want to refer to a static Java variable in my styles.xml, is that possible? Here's a pseudo-xml example:
<style name="Artwork">
<item name="android:background">@drawable/border_{Constants.MY_COLOR}</item>
</style>
I'm writing an android app that requires binding a JSON object into a domain entity with the keys from the JSON as instance variables. Since there are several domain entities, each with different instance variables that the JSON needs to bind to in the app, i'd like to write a method such as ths following: Loop through all the instance variables from the domain if a key exists in the JSON with the name of the instance variable, take the value for this key from the JSON and set the Domain's instance variable with this key name equal to this value. The reason i'm interested in the doing the binding from the class to the JSON is because if the JSON changes for some reason, I don't want it to break the app when the instance variable doesn't exist in the app's domain for a specific JSON key. Code...
View 2 Replies View RelatedI have an application that listens for screen off, and user present intents. Since you cant register to receive screen off intents from the manifest, I am registering them in a service. Do I really need to have a whole service to ensure that I always get notified of when the screen shuts off, and the user unlocks the phone? Seems really wasteful :-(
The code I use in my service:
@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "Service created.");
// register receiver that handles user unlock and screen off logic
IntentFilter filter = new IntentFilter(Intent.ACTION_USER_PRESENT);
filter.addAction(Intent.ACTION_SCREEN_OFF);
BroadcastReceiver mReceiver = new ScreenReceiver();
registerReceiver(mReceiver, filter);
}
if there are five text in a text view and we want to pass one of them on click event to the next class text view which method i m used on android
View 2 Replies View Relatedthis is the first class, displays listview from sql and pops up a option on longpress. I wanted to pass the ID number of the current select row to be processed on another class.
CODE:............................
Class AddText(extends Activity), Grafitti(extends MapActivity) and MarkerOverlay. Grafitti calls AddText, and AddText opens a new Activity that gets an input from user (EditText), then when that is successful Grafitti calls MarkerOverlay. The problem is I can't access the input in AddText. I need to use that input in MarkerOverlay, I tried creating a setter and getter but it won't work. (error) I've tried searching the web and I think the solution is Bundle. I'm having a hard time understanding how Bundle works. Is there any other way? or any code snippet on how to use Bundle. A code snippet would really help me a lot.
View 3 Replies View RelatedI have been trying to get "getExtra" to work but without success, I have a listview with 4 choices which launch a webpage within a webView class, when the user selects the option lets say option 3 I want to pass the value of 3 to the webView class so that it will load the correct webpage, at the moment all I get is errors, can somebody help with where I am going wrong.
View 3 Replies View RelatedI split my inner View class from my Main class into its own file. In my main class, I have the view set as an onTouchListener which records user movement into a matrix so it can translate and scale the view. After separating it everything works but im unsure how to pass the matrix to the View for onDraw to update. Any suggestions?
View 1 Replies View RelatedI am looking for an example that allows me to pass a custom class to a remote process. So far in the doc remote service example only an integer is passed i would like to pass a class on my own. I have implemented the parcelable protocol but i am really not sure how to pass that class. Any help please?
View 2 Replies View RelatedI am writing a class in Android that requires certain parameters from the class that calls its functions.
For Example my class is called "DoStuff"
DoStuff has 3 functions:
CODE:.....................
Is there a way for me to have canvas, tick and toggle implicetly passed to the "DoStuff" when I call on it's functions from somewhere else (that somewhere is unknown to DoStuff).
To describe my problem, everytime my location changes, it redraws the center maker on the map. Only catch is that it doesn't delete the previous one. I can get it to delete the previous one when the location is changed, but I have no idea how to pass the original overlay in-between classes.
View 1 Replies View RelatedCan I pass a singleton class's object from one activity to another activity using intent? I am using singleton class as image class img = image class.get Instance();, so i need the img instance for another activity, how can i pass an object instance in Android.
View 2 Replies View RelatedI want to pass a class reference to an activity, and then the activity will construct the view according to the content of the class.
How could I implement this function?
I want to show messageBox or notification when connection lost in Static DB class but i cant use getApplicationContext() because its a static class and i tried to call other class called notification but i have error so how i could pass activity object to my new class .
View 3 Replies View RelatedI have a class A which is responsible for fetching data from web services in android and i have a class B which is responsible for creating and rendering List View in android
Now how can i populate data on List View once the data is fetched successfully.
well i have following options but which one is better .. (if someone has anyother then i don't mind)
1) Create an intent of Class B and
pass the data that need to be
populated
2) Creating a static method int Class
B which will accept the data as an
argument and call setListAdapter
in class B i have used Holder Patter to create ListActivity. ( for reference List14.java in samples of Android )
I have an application App1 which defines class A and uses instances of this class. What I want to achieve is - after App1 is installed on the device to be able to load App2 which defines and implements class B which is subclass of class A (imported from App1 package); and be able to get an instance of class B in the App1. Class B doesn't add any new interfaces, so using it as class A is ok. But I am not sure how to pass the instance of class B to App1 (preferrably without any user interaction).
Can anyone advise if this is feasible?
I m doing some task with following code,
I want to access inner class variable from outer class method.
class Outer extends Activity
{private Handler mHandler = new Handler();
StopTheThread()
{mHandler.removeCallbacks(mUpdateTimeTask);//
This is the what I want to do:
} class Inner
{ final Runnable mUpdateTask = new = new Runnable() {
public void run() {
//Some Code Goes Here
} };
InnerClassMethod()
{ mHandler.removeCallbacks(mUpdateTimeTask);//
This statement working fine here. Here mUpdateTask is inner class variable which is not accessible from outer class.
I'm building an android application, which has a list view, and in the list view, a click listener, containing an onItemClick method. So I have something like this:
public class myList extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
getListView().setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
/* Do something*/
}
}
}
Normally, this works fine. However, many times I find myself needing too preform an application using the outer class as a context. thusfar, I've used: parent.getContext(); to do this, but I would like to know, is that a bad idea? I can't really call: because it's not really a subclass, just an embedded one. So is there any better way, or is that considered cosure? Also, if it is the right way, what should I do if the embedded method doesn't have a parameter to get the outside class?
I have two classes Screen1 and Screen2 both extends activity i have to pass data from the Screen1 to Screen 2
I wrote in onCreate method of Screen1 class
CODE:............
My doubt is ,how to receive myval data in Screen2 class ,what is the code i have to add in AndroidManifest.xml file
Is copying the reference to the object and not the value of the object. Meaning, when I modify pos.top or pos.bottom, the original object gets modified. I'm guessing I am missing a concept of pass object by reference vs value here which I thought I understood. What is the fix here? Is it a problem with how I defined my custom class?
View 2 Replies View Relatedthese is how to give a string as argument String link ="http://www.adobe.com /devnet/acrobat/pdfs /pdf_open_ parameters.pdf"; webview.loadUrl(link);But how to give an "URL" variable to load its content to webview.
View 1 Replies View Related