Android :: Custom Toast - Service Class Does Not Inherit The > FindViewById() Method
May 19, 2010The problem seems to be that the Service class does not inherit the > findViewById() method.
View 3 RepliesThe problem seems to be that the Service class does not inherit the > findViewById() method.
View 3 RepliesI am trying to execute a {public void} method in Service, from scheduled TimerTask which is periodically executing.This TimerTask periodically checks a condition. If it's true, it calls method via {className}.{methodName};However, as Java requires, the method needs to be {pubic static} method, if I want to use {className} with {.dot}.The problem is this method is for notification using Toast(Android pop-up notification) and Status Bar.But for this to work, the method must not have {static} modifier and resides in Service class.So, basically, I want background Service to evaluate condition from scheduled TimerTask, and execute a method in Service class.Can anyone help me what's the right way to use Service, invoking a method when certain condition is satisfied while looping evaluation?
View 1 Replies View RelatedI am trying to call my service class's stopService() method from my activity. But I don't know how to access stopservice method from my activity class. I have the below code but its not working. This is HomeScreen class:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
enablecheck = (CheckBox)findViewById(R.id.enablecheck);
enablecheck.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(enablecheck.isChecked()){
startService(new Intent(HomeScreen.this, AutoService.class));
} else {
stopService(new Intent(HomeScreen.this, AutoService.class));
} } });
}
This is Service Class:
public class AutoService extends Service {
private static final String TAG = "AutoService";
private Timer timer;
private TimerTask task;
@Override
public IBinder onBind(Intent intent) {
return null;
} @Override
public void onCreate() {
Toast.makeText(this, "Auto Service Created", Toast.LENGTH_LONG).show();
Log.d(TAG, "onCreate");
int delay = 5000; // delay for 5 sec.
int period = 5000; // repeat every sec.
timer = new Timer();
timer.scheduleAtFixedRate(task = new TimerTask(){
public void run() {
System.out.println("done");
} }, delay, period);
}
@Override
public boolean stopService(Intent name) {
// TODO Auto-generated method stub
timer.cancel();
task.cancel();
return super.stopService(name);
} }
I created a method called insertTable in a class called Table but i can't use it in my onClick method in the main class :
CODE:.......
I want to do a income.insertTable in the onClick method but eclipse say that i need to create a local variable.
I am using the following method in a new application I'm developing. There is a main activity, which instantiates different classes that extends RelativeLayout and I'm using setContentView to switch between the different modules of the application. I wonder if this is a good approach or necessarily I have to use different activities to the several screens the app haves.
View 1 Replies View RelatedI am trying to get the value of a EditText in a dialog box. A the "*"'ed line in the following code, the safeNameEditText is null; i am assuming because the 'findVeiwById' is searching on the context of the 'AlertDialog.OnClickListener';
How can I get/change the context of that 'findViewById' call?
CODE:.................
I develop an application. This don't use activity class. only use service class..
I need method(findviewbyid). but service don't have this method.
Is there any method to align toast message in application.By default it always appears at the bottom of application.
i did it like this...
Toast.makeText(this, "hello !", Toast.LENGTH_LONG).show();
I want to cancel a Toast to show the next one. This is the description of the behavious I want, when I select one element in the menu i display a toast from the actuel menu element, but if i switch from one element to an other quickly i'm creating a list of Toast to display. So i need to cancel the previous one but i never succed. This is an extract of my code: public class MainActivity extends TabActivity
private Toast toast; private String toastMsg;
private void toast(){ if(toast!=null){ toast.cancel(); } toast = Toast.makeText(MainActivity.this, toastMsg,Toast.LENGTH_SHORT);
toast.show(); } }
I have a custom title bar that I would like to apply to all my activities. I have searched online and found a few ways of doing that however I have ran into a problem. It seems that despite the fact I have a TextView in my titlebar with id @android:id/title, Android will not use the value defined in the manifest in android:label for each activity. I tried also calling setTitle(R.string.myTitle) but it still will not render it! If I manually put some text in my TextView in the xml it shows up fine. How can I have a custom title bar that is linked and makes Android use my manifest values for labels? I do not want to lose the setTitle() or the XML attributes functionality.
View 9 Replies View RelatedAnyone know if the latest update (1.47.651.1) is available to be applied to a toast's method rooted phone? i've seen some posts over at xda that refer to starting all over and bringing your device from stock to full root with the latest ota, but not sure if that's what i want (need) to do. the devs had the sd card fix update available as a stand alone update after being rooted. has the 1.47.651.1 become available to apply with my current status, or is the only way to implement it to start from scratch? anyone else in this situation?
View 5 Replies View Relatedfirst of all: yes, I read all the other threads on this topic. And not only those from this site... (you see, i'm a little frustrated) Most of them come with the advice to use "android:id" instead of just "id" in the xml file. I did. From others, i learned, that View.findViewById works different than Activity.findViewById. I handled that, too.
in my location_layout.xml i use
<FrameLayout .... >
<some.package.MyCustomView ... />
<LinearLayout ... >
<TextView ...
android:id="@+id/txtLat" />.................
Here's what I've figured out. I tried doing Toast's root method for linux and the directions weren't idiot proof because I screwed them up. I've explained how far I've gotten in other threads. If that's relevant just ask and I'll explain exactly what I did.
Anyway my phone does the basics. It allows me to make phone calls, text, and look at the internet on the phone so this isn't an emergency but it I am worse off than I was before I tried to root because I can no longer use easytether.
I had no problem with easytether prior to the root attempt, and it still works when I hook it up with my wifes untampered evo. with my phone but with my wife's evo, I've never messed with that one, I have no trouble connecting with easy tether.
Some of the things I've noticed about the device since the attmept...
-I can't update to 2.2 via the OTA or any other method, my device says no updates are available.
-Simple root wasn't so simple, the phone never shut off and rebooted into boot screen like the red screen said it would in step 1.
How do I reset the device to the way it was the day it was purchased. I've got everything I need backed up. I'm ready to reset just tell me how.
I have been reading myself in circles & am a bit confused on which way to go. I am enjoying the Evo but I would like the wireless tether. I guess there are other rooted things in the future I could install but the big draw for me is replacing my wmwifirouter on my WM device on my Evo.
I just don't know what the downsides are for one over other other. I think that Fresh has tethering already built in but I don't know if there are issues with the SD card or other items. Or should I just get the stock ROM that is rooted over at XDA?
I run service in the background I want to use Toast.makeText display message to run Activity.but I don't know Activity context I know Activity packageName and className.What should I do?
View 11 Replies View RelatedYou need a reference to the class that contains the method you want to call. To access the method homepage() inside the eSkyGuide from the class Weather, you need an instance of the eSkyGuide class inside the instance of the Weather class.
View 4 Replies View RelatedCan i call method of Listactivity from Activity class? I have creates Intent object of myListActivity class and called startIntent() from myActivity class.
View 3 Replies View RelatedI am a beginner in Android Developing. Can any1 please guide me how to call a Method of a class kept under other package. Like class A in Package 1 calls a method in Class B of Package 2 which returns An array or object. Do i have to create an Intent for that? actually i have to gather all information in 1 class from different classes kept under different packages.
View 2 Replies View RelatedI am writing a basic game engine and have an abstract class that represents any object that can be drawn in the 3D world, however inside this class is an abstract method Render() which I would like called automatically by the engine on each draw phase.
How could I implement this so that every class extending from my abstract class will automatically have Render() called? I am using java, android sdk 2.2, and opengl es
Is there any class or method for getting cdma signal strength I got for gsm but not for cdma in android??
View 1 Replies View RelatedI want to call a bitmap from a method in my main class and am unsure how to do it - I have a method: Code...
So basically, how can I place the bitmap in my detectFaces method in my main class and pass it as a bitmap on my imageview in my false class?
This question occured to me while programming a Android application, but it seems to be a general programming question more.
The situation is, I am extending (subclass-ing) an class from a library, and overriding a method. how do I know if I should invoke the method of super-class? and when? (in the beginning of the overridden method or in the end?)
For example, I am overriding the method "public boolean onCreateOptionsMenu(Menu menu)" from class "Activity" in Android platform. And I saw someone write "return super.onCreateOptionsMenu(menu)" in the end of the method, in an example. But how do I know it should be done this way? and it is correct or not? what's the difference if I begin my method with "super.onCreateOptionsMenu(menu)"?
I've been trying to call a non-static method, located in my main application Class, from the Preferences Class. Because the method I call is not static, I instantiate the main class and then try to call the specific method I want but it's force closing.
Preferences.class (from where I call the method):
Preference sorted = (Preference) findPreference("sortPref");
sorted.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
Object d = new Dmarks();
((Dmarks) d).queryBookmarks();
return true;
}});
the Dmarks.class method I call:
public void queryBookmarks() {
Toast.makeText(context, Toast.LENGTH_LONG).show();
//context is not null and the Toast is working if I call it from Dmarks.class }
The Logcat:
E/AndroidRuntime(11718): FATAL EXCEPTION: main
E/AndroidRuntime(11718): java.lang.NullPointerException
E/AndroidRuntime(11718):
at android.content.ContextWrapper.getContentReso
lver(ContextWrapper.java:90)
E/AndroidRuntime(11718):
at android.app.Activity.managedQuery(Activity.ja
va:1520)
E/AndroidRuntime(11718):
at com.droidil.droidmarks.Dmarks.queryBookmarks(
Dmarks.java:101)
E/AndroidRuntime(11718):
at com.droidil.droidmarks.Preferences$2.onPrefer
enceChange(Preferences.java:47)
E/AndroidRuntime(11718):
at android.preference.Preference.callChangeListe
ner(Preference.java:756)
E/AndroidRuntime(11718):
at android.preference.ListPreference.onDialogClo
sed(ListPreference.java:219)
E/AndroidRuntime(11718):
at android.preference.DialogPreference.onDismiss
(DialogPreference.java:384)
E/AndroidRuntime(11718):
at android.app.Dialog$ListenersHandler.handleMes
sage(Dialog.java:1047)
E/AndroidRuntime(11718):
at android.os.Handler.dispatchMessage(Handler.ja
va:99)
E/AndroidRuntime(11718):
at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(11718):
at android.app.ActivityThread.main(ActivityThrea
d.java:4627)
E/AndroidRuntime(11718):
at java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime(11718):
at java.lang.reflect.Method.invoke(Method.java:5
21)
E/AndroidRuntime(11718):
at com.android.internal.os.ZygoteInit$MethodAndA
rgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(11718):
at com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:626)
E/AndroidRuntime(11718):
at dalvik.system.NativeStart.main(Native Method)
D/dalvikvm(11718): GC_FOR_MALLOC freed 4248 objects / 282248 bytes in 40ms
W/ActivityManager( 244): Force finishing activity com.droidil.droidmarks/.Preferences
I have code which has one activity which passes information to a second activity.
I can use this information to pass to a third activity with additional information from the result of the second activity.
I want to use gestures as a method of going back to a previous activity, but if I go back from the third to the second activity I need the information initially passed from the first to the second activity to still be present.
i.e.
First Acticity
what is Y?
answer y = 5
Second activity
User said Y = 5
what is X?
Third Activity
User said Y = 5
X = 6
Go back to Second activity but maintain the input of
User said Y = 5.
To do this I have used a bundle to pass the information between activities, but I can only access the info in the bundle from within a method within the class started by the intent.
The gesture controls are within another class, so I cannot access the bundle information from within this class as the getIntent command produces a not defined error.
What I need to do is to be able to pass the information from the bundle from the first activity to the gesture class so that I can pass it back when I go back using the gestures.
Since API 7, PhoneStateListener has a function: void onSignalStrengthsChanged( SignalStrength signalStrength )
Question: how can I override this via reflection so that I can stay backwards compatible with earlier APIs that don't have the SignalStrength class ? If I make the argument an Object, the signature changes of course.
I try to make android java app that uses webkit browser component but in slight different way. My primary goal is to modify the webkit WebViewCore java class method so my android application uses my own WebView which derived from modified WebViewCore and acts as I wish. The problel is that WebViewCore and entire bunch of related classes is not part of public SDK.
So far I tried:
- replaced android.jar from SDK in my project with "full" version (framework.jar)
- copied entire webkit java classes from Android OS to my project and modified the method as I need.
- included in lib/armeabi the libwebcore.so and libchrome_net.so (these I grabbed from rooted phone which I gonna to use for experiments)
- compiled and created apk file with libs included (in the code java layer calls my own libs using System.loadLibrary(..))
- application crashes on launch on device with:
Code:
04-18 10:39:23.451: D/dalvikvm(8214): Trying to load lib /data/data/com.tester.webtest/lib/libwebcore2.so 0x2bb4a1c8
04-18 10:39:23.511: D/dalvikvm(8214): Added shared lib /data/data/com.tester.webtest/lib/libwebcore2.so 0x2bb4a1c8
04-18 10:39:23.521: D/dalvikvm(8214): Trying to load lib /data/data/com.tester.webtest/lib/libchromium_net2.so 0x2bb4a1c8
04-18 10:39:23.531: D/dalvikvm(8214): Added shared lib /data/data/com.tester.webtest/lib/libchromium_net2.so 0x2bb4a1c8
04-18 10:39:23.541: D/dalvikvm(8214): No JNI_OnLoad found in /data/data/com.tester.webtest/lib/libchromium_net2.so 0x2bb4a1c8,
[code]....
What should I do for making my own independent version of webkit, so I can install it with my application on specific phone without breaking other apps (browsers) behaviour?
I'm creating my own View class, and defining custom xml attributes with a attrs.xml. As long as I provide each attribute manually, there is no problem, but
code:...................
The android:text is properly set in my instance, but the borderDrawable is not. I guess this has something to do with namespaces, because inside the styles.xml, the name="mypack:borderDrawable" is not handled by the XML parser's namespace facility, because its inside an attribute value. So "mypack" is in no way connected to "http://some.weird.url.com/seems/not/to/ matter" and adding it via xmlns:mypack... to the stylefile would not help, I guess. In the same file, "android:text" is somehow recognized, even though "android" is AFAIK only a ns-defintion for [url], which is also not declared in that file.
So what is the proper way to set a custom attribute in a style?
When using setDuration for a Toast is it possible to set a custom length or at least something longer than Toast.LENGTH_LONG?
View 4 Replies View RelatedEverything is in the title.
On the official documentations it is stated that Note that services, like other application objects, run in the main thread of their hosting process and AsyncTask only works if it is executed in the UIThread.
So is it possible to use AsyncTask in a Service class? code...
I have the folowing method in a Service in my appplication: Code... Do I have to do an AIDL or is there a simpler way?
View 2 Replies View Related