Android :: Class Derived From Intent Service Must Have Default Constructor

May 8, 2009

I'm posting this to share the lessons I learned while working with IntentService. IntentService has a single constructor that takes a string argument "name". The documentation has no description of what name is used for. In looking at the sources, I found that its only use is in naming the worker thread for the IntentService. This thread is named IntentService [name].

I initially implemented the constructor of the derived class to also take a String argument and passed it along to the derived class. This is wrong. This will cause the startService() call to generated a java.lang.InstantiationException in the application containing the service i.e. you don't get the exception in the application calling startService(). A clue to the actual problem is a little further up in the logs:"newInstance failed: no <init>()"

The derived class must have a Default constructor and that constructor must call super() passing a string for the name component of the worker thread name.
public class MyIntentService extends IntentService {
public MyIntentService() { super("MyIntentService");
} @Override
protected void onHandleIntent(Intent intent) {
// Handle events on worker thread here }

Android :: Class derived from Intent Service must have default Constructor


Android :: What Is The Significance Of Context In Various Constructor Of Intent Class When Starting An Activity

Mar 4, 2010

I had come across a code snippet which calls for an activity without referring to any context. Before, i was considering that context is used to tell about the calling component. But as i came see that another component can be called without any reference to context, it makes me wonder what purpose it might be serving. please put some light on it.

Here is the code which calls for an activity without referring to 'context'

CODE:............................

View 1 Replies View Related

Android :: Using Class Derived From Text / View

Jun 19, 2010

CoreStartHere.java
public class CoreStartHere extends TabActivity {
t = getTabHost();
t.newTabSpec("tTask");
t.setIndicator(...);
t.setContent(new Intent().setClass(this, T1Task.class);
} t1Task.java
T1Task extends Activity {
onCreate(Bundle ...) {
:
myListview = (ListView) findViewById(R.id.hdListView);
myEditText = (EditText) findViewById(R.id.hdEditText);
hdItems = newArrayList <String>();
aa = new ArrayAdapter <String>(this, R.layout.hditemview, hdItems);
:
setOnKeyListener (new OnKeyListener() {
onKey(...) {
:
hdItems.add(0, myEditText.getText().toString());
aa.notifyDatasetChanged();
:
} } } }
hditemview.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
class="com.a1.hd.hdRecordTaskListItemView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:scrollbars="vertical"
android:textColor="@color/HD_Text"
android:fadingEdge="vertical"
/>hdRecordTaskListItemView.java
hdRecordTaskListItemView extends TextView {
// has 3 constructors
// onDraw
}
None of the constructor in hdRecordTaskListItemView get invoked and not surprisingly onDraw does not get called either. The text appears with the default style. The onDraw is supposed to draw on the "canvas".

View 1 Replies View Related

Android :: Loading Layout From XML Inside Of Derived Class

Mar 4, 2010

Right now I have a class that extends LinearLayout and builds the view inside of the constructor using a series of addViews. I wanted to move this into an XML file, so I have the same view defined there. My problem is that I can't figure out how to load the XML file in the constructor of the derived class. I looked up the LayoutInflater stuff, but I wasn't entirely sure how to use it in that context. Do I need to call addView() with the result of the LayoutInflater? Is this even possible? The other issue is that the context object that is passed in doesn't have the LayoutInflater methods. I'm not sure if I need an instance of Activity to do that.

View 3 Replies View Related

Android :: Pass Enumerators To An Activity Constructor From An Intent?

May 14, 2010

I have an activity that when started needs access to two different ArrayLists. Both Lists are different Objects I have created myself.

Basically I need a way to pass these objects to the activity from an Intent. I can use addExtras() but this requires a Parceable compatible class. I could make my classes to be passed serializable but as I understand this slows down the program.

What are my options?

Can I pass an Enum?

As an an aside: is there a way to pass parameters to an Activity Constructor from an Intent?

View 3 Replies View Related

Android :: How To Use Parcelable - If Class Requires Additional Parameters In Constructor

May 20, 2010

I'm trying to create class with generics that will have ability to serialize its state using Parcelable interface.
The problem is that class has to contain constructor with single parameter - Parcel, but in my case I need to create class with additional parameters.
Besides, Parcelable.Creator doesn't allow to use generics.

Here is an example:

public class Sample<T> { ...

public Sample(Context ctx, SomeInterface iface, Parcel parcel) {...}

...}

What is the best practice to do it?

View 1 Replies View Related

App Crash Every Time Try To Call Constructor Code From Map Class

Oct 10, 2013

I'm developing an app that uses google maps, but for some reason it crashed every time I try to call the constructor code from the map class.

main
[HIGH]import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {

[Code] ......

View 2 Replies View Related

Android :: Dalvik Message - Default Buffer Size Used In BufferedInputStream Constructor

Aug 17, 2010

When I used BufferedInputStream and I specify a buffer size, Dalvik gives me this warning - Default buffer size used in BufferedInputStream constructor. It would be better to be explicit if an 8k buffer is required.
But right now, my buffer size is already at 8k. What am I doing wrong?

View 1 Replies View Related

Android :: Unable To Start Service Intent Service Not Found

Aug 20, 2009

I am getting following message when i try to launch service.Also is there any specific path on file system where we need to place the .apk file which contains my serivce component only.

View 2 Replies View Related

Android :: Passing Intent Value To Another Class

Oct 14, 2010

I have four groups in a listview each with four url's I want to load in a webView. When the user select a url to goto I set a value like so;

if (position == 0) webb = webb +2;
{
Intent intent = new Intent(this, official.class);
startActivity(intent);
}

I then carryout the intent to move to the webView class where I have given each URL a value like so;

if (webb == 2) mWebView.loadUrl("http://yahoo.com");
if (webb == 3) mWebView.loadUrl("http://www.bbc.co.uk");

But the screen stays blank, if I state the value inside the official.class it works. How can I get this value to pass to another class based on the selection the user makes from the listview.

View 3 Replies View Related

Android :: Passing Intent Value From One Class To Another

Oct 16, 2010

I 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 I get no errors, but the app force closes when I select the option, could this be due to having to announce this in the manifest? can somebody help with where I am going wrong. This is my intent

public void onListItemClick(ListView l, View v, int position, long id) {
if (position == 0) {
Intent intent = new Intent(this, official.class);
intent.putExtra("weburl", 3);
startActivity(intent);}
This is the official class:
public class official extends Activity {
int number = getIntent().getIntExtra("weburl", 0);
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
} return super.onKeyDown(keyCode, event);
} WebView mWebView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.browser1);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
if (number == 2) mWebView.loadUrl("http://bcafc.livewwware.co.uk");
if (number == 3) mWebView.loadUrl("http://www.bbc.co.uk");
mWebView.setWebViewClient(new HelloWebViewClient());

View 1 Replies View Related

Android :: How To Access Intent Value In Another Class?

May 5, 2010

I had write two classes IntentA and IntentB in my application (Both are in same package and both extends Activity class). In IntentA class I had created one button on pressing that button controll is trsnfer to IntentB class. IntentB class also contain Button on pressing that control is transfer to IntentA class.

This work fines. Now I want to set value in IntentA class using putExtra method and access that value in IntentB class How should I do that? I had put value in class IntentA like

Intent i1 = new Intent(this,IntentB.class);
i1.putExtra("Intent Name", "IntentA");
startActivity(i1);

Now I don't know How to access "Intent Name" value in IntentB class.

View 5 Replies View Related

Android : Way To Use Intent From Non-activity Class?

Jan 2, 2010

I have three classes one main-activity(named MainMap), one non-activity class(named MyItemizedOverlay), and one activity class(named AudioStream). I want to start AudioStream activity from non-activity class but i don't know how to.

View 1 Replies View Related

Android :: Set An Intent's Class From A String Value?

Jun 10, 2010

I am trying to set the class for an intent to the address listed in a string value, so that I can launch a given activity. The string is composed dynamically during runtime.

Is there anyway to make something like the code below run...

View 2 Replies View Related

Android :: Launching Intent From Class Outside An Activity

Jul 28, 2010

I've got two activities, one of them is called MyActivity. I want both of them to be able to use a function located in a class othat we may call MyClass. In MyClass, I try to use an intent to launch the activity AnotherActivity. Since the constructor takes a context as parameter, I simply tried to store a context from the activity in the constructor, and then use it when I try to create my intent.However, even thought none of the arguments are null (checked that with a simple if-statement), intent seems to be null and a NullPointerException is thrown. Why does it not work, and what can I do to solve the problem?
I'm quite new to Android and Java development, so please explain it as basic as you can.

View 2 Replies View Related

Android :: Transport Own Class With Intent Between Objects/

Jul 20, 2010

I'm programming an android application using the StartActivityForResult() - Method.
But, i want to get as result an own class, not a string or something like that.
how can i tell the intent to use the class i wrote to give back?

View 2 Replies View Related

Android : Droid Calling Intent From Another Class?

Jun 29, 2010

I am calling intents alot in my program and I thought that I could write a public class that would have all of my intents so I can just call something like intents.testIntent(params) and then have it fire off the intent.

I tried it out but am getting a force close with a null pointer exception. This is my whole class. I know it is probably sloppy but I have just been learning java for 2 months so I still am an amateur. Any way, my code...

View 1 Replies View Related

Android : Pssible To Have Extending Intent Class?

Jul 28, 2009

I was experimenting with extending the Intent class but don't seem to make it work properly. I am wondering if extending is even possible. Here is the snippets.

Code for custom intent: Code...

View 3 Replies View Related

Android :: Can We Pass Singleton Class's Object Via Intent?

Sep 3, 2010

Can 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 Related

Android :: Way To Identify Phone Intent Type From Another Class?

Aug 18, 2010

I create an Intent in one class then it's returned to another class. I need to check the type of intent it is. I need to ensure it's not a specific class of intent.

View 1 Replies View Related

Android :: Intent - Receive Myval Data In Screen2 Class?

Feb 24, 2009

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

View 6 Replies View Related

Android : Launch Browser Intent With Custom Class - Cannot Find Activity

Jul 25, 2010

I want to specifically run the default Android browser for a given URL. I'm using this code: I also tried adding <uses-library android:name="com.google.android.browser" /> to the manifest. Am I missing something here? PS: I'm not interested in using startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"))) as it will list all the choices for the browsing Intent.

View 3 Replies View Related

Android :: Possible To Use AsyncTask In A Service Class?

May 1, 2010

Everything 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...

View 5 Replies View Related

Android :: Ue Intent In Service?

Aug 3, 2010

I want startActivity in the service.first I new Intent(),but I don't know how to new Intent().Because Activity and Service don't together project.I don't know Intent how to find this Activity.

View 2 Replies View Related

Android :: Class Name Of Media Scanner Service?

Sep 1, 2010

What is the class name of media scanner service?

View 2 Replies View Related

Android :: UI Blocking On Intent Service?

Sep 14, 2010

I'm launching an IntentService using startActivity from inside the onClickListener of a button. startActivity returns immediately. No blocking there. But the button stays "pressed" until the IntentService finishes its work. In addition, the screen does not respond to rotation while the IntentService thread is running. I can see that it's a separate thread in the debugger but the UI seems to be coupled to it. As soon as the IntentService thread finishes, the UI is unblocked. Any idea how I can prevent this and let the UI continue?

View 2 Replies View Related

Android :: How To Get Intent Received By A Service?

Dec 27, 2009

I'm starting a service with an intent where I put extra information. How can I get the intent in the code of my service? There isn't a function like getIntent().getExtras() in service like in activity.

View 1 Replies View Related

Android :: Cannot Start Service If Inner UpdateService Class Not Static

Oct 2, 2009

if the inner UpdateService class is not static, it cannot start the service. The ActivityManager complains "Unable to start service Intent"...

View 8 Replies View Related

Android :: Cannot Open Database In Service Layer Class

Sep 15, 2010

When I create a instance of the SQLiteOpenHelper, I always need a "Context" to be passed as its constructor's argument. To use this "Context", in my service layer class, I extends Activity class, though I do not display this activity on the screen because it is my service layer. I always get NullPointer exception when I open the SQLiteOpenHelper in my service layer class, Is it because my service layer class extends the Activity class but I did not show this activity on mobile screen? (That's there is no intent to my service layer class), if it is so, how to get rid of it if I wanna open a SQLiteOpenHelper in my service layer class which do not need to extends Activity, but need a Context object to pass to SQLiteOpenHelper?

View 2 Replies View Related

Android :: Run In Background - Service Vs. Standard Java Class

Jun 18, 2010

In Android, if I want to do some background work, what is the difference between

Creating a Service to do the work, and having the Activity start the Service VS. Creating a standard java class to do the work, and having the Activity create an object of the class and invoke methods, to do the work in separate thread.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved