Search Results

Search found 1008 results on 41 pages for 'oncreate'.

Page 6/41 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • Android : launching diff activities under TabWidget

    - by rahul
    hiii I am trying to launch activities under each tab. I hav tried with following code public class Tab_Proj1 extends TabActivity { TabHost mTabHost ; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final Context context = getApplicationContext(); //mTabHost = (TabHost) this.findViewById(R.id.); mTabHost = getTabHost(); mTabHost.setup(); mTabHost.addTab(mTabHost.newTabSpec("tab_test4") .setIndicator("Contacts") .setContent(new Intent().setClass(context, Tab1Activity.class))); Tab1Activity is extending ListActivity. I m getting exception as:::::: 01-25 11:57:07.352: ERROR/AndroidRuntime(952): Uncaught handler: thread main exiting due to uncaught exception 01-25 11:57:07.382: ERROR/AndroidRuntime(952): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.app.Tab_Proj1/com.android.app.Tab_Proj1.Tab_Proj1}: java.lang.RuntimeException: Could not create tab content because could not find view with id 2131034148 01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268) 01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284) 01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.app.ActivityThread.access$1800(ActivityThread.java:112) 01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692) 01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.os.Handler.dispatchMessage(Handler.java:99) 01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.os.Looper.loop(Looper.java:123) 01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.app.ActivityThread.main(ActivityThread.java:3948) 01-25 11:57:07.382: ERROR/AndroidRuntime(952): at java.lang.reflect.Method.invokeNative(Native Method) 01-25 11:57:07.382: ERROR/AndroidRuntime(952): at java.lang.reflect.Method.invoke(Method.java:521) 01-25 11:57:07.382: ERROR/AndroidRuntime(952): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782) 01-25 11:57:07.382: ERROR/AndroidRuntime(952): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540) 01-25 11:57:07.382: ERROR/AndroidRuntime(952): at dalvik.system.NativeStart.main(Native Method) 01-25 11:57:07.382: ERROR/AndroidRuntime(952): Caused by: java.lang.RuntimeException: Could not create tab content because could not find view with id 2131034148 01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.widget.TabHost$ViewIdContentStrategy.(TabHost.java:539) 01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.widget.TabHost$ViewIdContentStrategy.(TabHost.java:530) 01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.widget.TabHost$TabSpec.setContent(TabHost.java:417) 01-25 11:57:07.382: ERROR/AndroidRuntime(952): at com.android.app.Tab_Proj1.Tab_Proj1.onCreate(Tab_Proj1.java:52) 01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123) 01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231) ====================================================================== Am I going in correct way? If not please help me with some ideas..... thanks

    Read the article

  • Android ProgressBar.setProgressDrawable only works once?

    - by Chuck
    In a color picker, I have 3 SeekBars for Hue, Saturation, and Value. Calling setProgressDrawable on these SeekBars only works once -- at initialization from onCreate. When the user updates the Hue SeekBar, I want to call setProgressDrawable for the Saturation and Value SeekBars, to show the user their color choices for the new Hue. But all calls to setProgressDrawable (after the initial ones from onCreate) cause the SeekBar to be blanked. How can I update the background gradient of my SeekBars based upon user input? Thanks! Chuck

    Read the article

  • Android -- Change the AlertDialog Animation?

    - by borg17of20
    Hello all, Does anyone know how to change the in/out animations of an extended AlertDialog? I connot figure out how to do this. See below for what I have so far (it doesn't work though): public class PauseMenu extends AlertDialog { private Context myContext; public PauseMenu(Context context, int theme) { super(context, theme); myContext = context; } protected PauseMenu(Context context, boolean cancelable, OnCancelListener cancelListener) { super(context, cancelable, cancelListener); myContext = context; } public PauseMenu(Context context) { super(context); myContext = context; } @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub //super.onCreate(savedInstanceState); this.setContentView(R.layout.pause_menu); //this.getWindow().getDecorView().setAnimation(new ViewZoomAnimation()); this.getWindow().getDecorView().setAnimation(AnimationUtils.loadAnimation(myContext, R.anim.slide_in_bottom_newgame)); } } Thanks.

    Read the article

  • How to attach a scroll bar to a canvas in android ?

    - by panzerschreck
    Hello, I am drawing up a grid on a canvas as below, I have not been able to get the scroll bar to appear, I looked around for examples, but none of them give details on drawing scroll bars for custom views. Your help is much appreciated. public class GridActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // i tried to do as in the documentation nothing seems to happen LinearLayout lLayout = new LinearLayout(this); lLayout.addView(new CustomDrawableView(this), new ViewGroup.LayoutParams(800,600)); FrameLayout fLayout = new FrameLayout(this); fLayout.addView(lLayout, new ViewGroup.LayoutParams(800,600)); setContentView(fLayout); } private class GridView extends ScrollView { private ShapeDrawable[] mDrawable; public GridView (Context context) { // some initialization } protected void onDraw(Canvas canvas) { for each i mDrawable[i].draw(canvas) } } }

    Read the article

  • how to set custom title bar TextView Value dynamically in android?

    - by UMMA
    friends, i have created custom title bar using following titlebar.xml file with code <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/myTitle" android:text="This is my new title" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textColor="@color/titletextcolor" android:layout_marginLeft="25px" android:paddingTop="3px" /> and java code to display custom title bar on each activity. @Override public void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mytitle); super.onCreate(savedInstanceState); setContentView(R.layout.main); } now i want to set textview value dynamically in each activity can any one guide me how can i achieve this? using findviewbyid here i dont get reference of that textview to set value because main layout does not contains any textbox with such a name but mytitle. any help would be appriciated.

    Read the article

  • sqllite and populating list view, android

    - by Rob Bushway
    I am populating a text and list view from a sqllite database. The data is populating from the cursor correctly (I see the list filling with text rows), but I'm not able to see the actual text in the rows - all I see are empty rows. For the life of me, I can't figure out what I'm not able to see the data in the text rows. My layouts: Tab layout: list layout: row layout: <?xml version="1.0" encoding="utf-8"?> / My topics activity package com.gotquestions.gqapp; import com.gotquestions.gqapp.R.layout; import android.R; import android.app.ListActivity; import android.database.Cursor; import android.database.SQLException; import android.os.Bundle; import android.widget.SimpleCursorAdapter; public class TopicsActivity extends ListActivity { private DataBaseHelper myDbHelper; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // DataBaseHelper myDbHelper = new DataBaseHelper(this); myDbHelper = new DataBaseHelper(this); //test try { myDbHelper.openDataBase(); }catch(SQLException sqle){ throw sqle; } setContentView(layout.list_layout); Cursor c = myDbHelper.fetchAllTopics(); startManagingCursor(c); String[] from = new String[] { DataBaseHelper.KEY_TITLE }; int[] to = new int[] { R.id.text1 }; // Now create an array adapter and set it to display using our row SimpleCursorAdapter notes = new SimpleCursorAdapter(this, layout.notes_row, c, from, to); setListAdapter(notes); myDbHelper.close(); } } My database helper: package com.gotquestions.gqapp; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.gotquestions.gqapp/databases/"; private static String DB_NAME = "gotquestions_database.mp3"; public static final String KEY_TITLE = "topic_title"; public static final String KEY_ARTICLE_TITLE = "article_title"; public static final String KEY_ROWID = "_id"; private static final String TAG = null; private SQLiteDatabase myDataBase; // private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @param context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we are gonna be able to overwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException{ //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Override public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); db.execSQL("DROP TABLE IF EXISTS titles"); onCreate(db); } public Cursor getTitle(long rowId) throws SQLException { Cursor mCursor = myDataBase.query(true, "topics", new String[] { KEY_ROWID, KEY_TITLE }, KEY_ROWID + "=" + rowId, null, null, null, null, null); if (mCursor != null) { mCursor.moveToFirst(); } return mCursor; } public Cursor fetchAllTopics() { return myDataBase.query("topics", new String[] {KEY_ROWID, KEY_TITLE}, null, null, null, null, null); }; public Cursor fetchAllFavorites() { return myDataBase.query("articles", new String[] { KEY_ROWID, KEY_ARTICLE_TITLE}, null, null, null, null, null); }; }

    Read the article

  • Syntax error on token "QUOTE", VariableDeclaratorId expected after this token

    - by user356812
    I've posted a bigger chunk of the code below. You can see that initially QUOTE was procedural- coded in place. I'm trying to learn how to use declarative design so I want to do the same thing but by using resources. It seems like I need to access the string.xml thru the @R.id tag and identify QUOTE with that string value. But I don't know enough to negotiate this. Any tips? Thanks! public class circle extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new GraphicsView(this)); } static public class GraphicsView extends View { //private static final String QUOTE = "Happy Birthday to David."; private final String QUOTE = getString(R.string.quote); ..... @Override protected void onDraw(Canvas canvas) { // Drawing commands go here canvas.drawPath(circle, cPaint); canvas.drawTextOnPath(QUOTE, circle, 0, 20, tPaint);

    Read the article

  • [android] Activity group throw ActivityNotFoundException?

    - by Mak Sing
    Hi, I want to change the current activity inside a tab in a tab activity, after some research, I know that I need to use activity group to go this. then I created a new class extends ActivityGroup with the code below: public class FavShop extends ActivityGroup{ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LocalActivityManager m = getLocalActivityManager(); Intent i = new Intent(this, fav_shops.class); Window window = m.startActivity("favourite shop",i); setContentView(window.getDecorView()); } } then I run the program, the program throw the ActivityNotFoundException when the intent for the tab is launched I have no idea how to solve this problem, could anyone help me?

    Read the article

  • Android 2.1 View's getDrawingCache() method always returns null

    - by Impression
    Hello, I'm working with Android 2.1 and have the following problem: Using the method View.getDrawingCache() always returns null. Example code: public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final View view = findViewById(R.id.ImageView01); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); final Bitmap bmp = view.getDrawingCache(); System.out.println(bmp); } I've already tried different ways to configure the View object for generating the drawing cache (e.g. View.setWillNotDraw(boolean) and View.setWillNotCacheDrawing(boolean)), but nothing works. What is the right ways, or what do I wrong?

    Read the article

  • How to write onclick event for ListView in Android?

    - by Srikanth Naidu
    Hi i have the listview the sixitems in it, but when i call alet function on event it doesnt work ? let me know how to write a function on item event on click? public class PhotoListView extends ListActivity { String[] listItems = {"HeadShot", "BodyShot ", "ExtraShot", "Video Take1", "Video Take2", "Video Take3", }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setListAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1, listItems)); } OnListclick ListView Shot = getListView(); protected void onListItemClick(View view) { if(view == Shot){ AlertDialog.Builder alertbox = new AlertDialog.Builder(this); // set the message to display alertbox.setMessage("Please Get Ready"); }

    Read the article

  • how to set listviewadapter in android custom dialog?

    - by UMMA
    hi, i am using following code to setlistview adapter but giving me error at last line public class MyCustomDialog extends Dialog { String[] items= {"lorem", "ipsum", "dolor", "sit", "amet", "consectetuer", "adipiscing", "elit", "morbi", "vel", "ligula", "vitae", "arcu", "aliquet", "mollis", "etiam", "vel", "erat", "placerat", "ante", "porttitor", "sodales", "pellentesque", "augue", "purus"}; TextView selection; public MyCustomDialog(Context context) { super(context); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mylistviewdialog); ListView lst=(ListView)findViewById(R.id.mylist); lst.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, items)); // error here The constructor ArrayAdapter<String>(MyCustomDialog, int, String[]) is undefined } } please guide what mistake am i doing? any help would be appreciated.

    Read the article

  • NullPointerException when Using requestWindowFeature(Window.FEATURE_NO_TITLE) on ListActivity Extending Activity

    - by ColorWP.com
    I have a ListActivity extending class and I am trying to hide the default TitleBar (I think it's called ActionBar) using the code below. It works on a regular activity, but not on the ListActivity. How do I accomplish the same in this scenario? public class MyClass extends ListActivity{ @Override public void onCreate(Bundle b) { requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(b); // Tried Window.FEATURE_NO_TITLE here as well setContentView(R.layout.activity_myclass); getActionBar().setDisplayHomeAsUpEnabled(true); } }

    Read the article

  • Android setImageURI out of memory error

    - by Improver
    I have a very small activity that must show an image. If picture is not very small (for example 1.12 Mb 2560x1920) it produces out of memory on change screen orientation. I tried getDrawable.setCallback(null) but no luck. Where am I wrong? public class Fullscreen extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); System.gc(); setContentView(R.layout.fullscreen); ImageView imageView = (ImageView) findViewById(R.id.full_screen_image); long imageId = 2; imageView.setImageURI(Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + imageId)); } }

    Read the article

  • Android: Using onStart() method in Bluetooth application

    - by Nii
    Hello, I am getting a nullpointer exception when my onStart() method is called. Here is the breakdown of my Android app: Opening the app brings a user to the homescreen: The user is then presented with the first 6 icons to choose from. When the user presses the "Sugar" icon it takes them to the SugarTabActivity. The SugarTabActivity is a Tabbed layout with two tabs. I'm concerned with the first tab. The first tab calls the getDefaultAdapter() method in its onCreate() method. Once it calls this, it checks if the bluetooth adapter is null on the phone, and if its null it shows a toast saying "Bluetooth is not available". This works just fine. Then I call the onStart() method. In the onStart() method I check if bluetooth is enabled, and if it isnt, then I start a new activity from the BluetoothAdapter enable bluetooth intent; otherwise, I start my bluetooth service. The exact error I'm getting is 04-19 00:44:45.674: ERROR/AndroidRuntime(225): Caused by: java.lang.NullPointerException 04-19 00:44:45.674: ERROR/AndroidRuntime(225): at com.nii.glucose.Glucose.onStart(Glucose.java:313). Heading Override public void onCreate(Bundle icicle) { super.onCreate(icicle); if(D) Log.d(TAG, "+++ ON CREATE +++"); setContentView(R.layout.glucose_layout); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if(mBluetoothAdapter==null){ Toast.makeText(this, "Bluetooth not available", Toast.LENGTH_LONG).show(); //finish(); return; } } Override public void onStart() { super.onStart(); if(D) Log.e(TAG, "++ ON START ++"); // If BT is not on, request that it be enabled. // setupChat() will then be called during onActivityResult if (!mBluetoothAdapter.isEnabled()) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); // Otherwise, setup the chat session } else { if (mGlucoseService == null) mGlucoseService = new BluetoothService(this, mHandler); } } @Override public synchronized void onResume(){ super.onResume(); if(D) Log.e(TAG,"==== ON RESUME ======"); // Performing this check in onResume() covers the case in which BT was // not enabled during onStart(), so we were paused to enable it... // onResume() will be called when ACTION_REQUEST_ENABLE activity returns. if (mGlucoseService != null) { // Only if the state is STATE_NONE, do we know that we haven't started already if (mGlucoseService.getState() == BluetoothService.STATE_NONE) { // Start the Bluetooth chat services mGlucoseService.start(); } } } @Override public synchronized void onPause(){ super.onPause(); //isActive.set(false); if(D) Log.e(TAG,"==== ON PAUSE ======"); } @Override public void onDestroy() { super.onDestroy(); // Stop the Bluetooth chat services if (mGlucoseService != null) mGlucoseService.stop(); if(D) Log.e(TAG, "--- ON DESTROY ---"); }

    Read the article

  • how to play video from url

    - by priyanka
    i am biginner in android development and try to play video from link but it's give error "sorry,we can't play this video" i tride so many links but for all links its show same error. My code it follwing public class VideoDemo extends Activity { private static final String path ="http://demo.digi-corp.com/S2LWebservice/Resources/SampleVideo.mp4"; private VideoView video; private MediaController ctlr; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); getWindow().setFormat(PixelFormat.TRANSLUCENT); setContentView(R.layout.videoview); video = (VideoView) findViewById(R.id.video); video.setVideoPath(path); ctlr = new MediaController(this); ctlr.setMediaPlayer(video); video.setMediaController(ctlr); video.requestFocus(); } } thansk in advance

    Read the article

  • setting picture captured by built-in camera into an ImageView

    - by MAkS
    in my app i m calling built in camera for capturing picture but i want to set that picture into an image view following is the code . so what code should i add to it to set the picture into imageview. public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intent, 0); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK && requestCode == 0) { String result = data.toURI(); // ... } } Thanks in advance

    Read the article

  • ClassCastException when casting custom View subclass

    - by Jens Jacob
    Hi I've run into an early problem with developing for android. I've made my own custom View (which works well). In the beginning i just added it to the layout programmatically, but i figured i could try putting it into the XML layout instead (for consistency). So what i got is this: main.xml: [...] <sailmeter.gui.CompassView android:id="@+id/compassview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/widget55" android:background="@color/white" /> [...] CompassView.java: public class CompassView extends View { } SailMeter.java (activity class): public class SailMeter extends Activity implements PropertyChangeListener { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); compassview = (CompassView) findViewById(R.id.compassview1); [...] } } (Theres obviously more, but you get the point) Now, this is the stacktrace: 05-23 16:32:01.991: ERROR/AndroidRuntime(10742): Uncaught handler: thread main exiting due to uncaught exception 05-23 16:32:02.051: ERROR/AndroidRuntime(10742): java.lang.RuntimeException: Unable to start activity ComponentInfo{sailmeter.gui/sailmeter.gui.SailMeter}: java.lang.ClassCastException: android.view.View 05-23 16:32:02.051: ERROR/AndroidRuntime(10742): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596) 05-23 16:32:02.051: ERROR/AndroidRuntime(10742): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621) 05-23 16:32:02.051: ERROR/AndroidRuntime(10742): at android.app.ActivityThread.access$2200(ActivityThread.java:126) 05-23 16:32:02.051: ERROR/AndroidRuntime(10742): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932) 05-23 16:32:02.051: ERROR/AndroidRuntime(10742): at android.os.Handler.dispatchMessage(Handler.java:99) 05-23 16:32:02.051: ERROR/AndroidRuntime(10742): at android.os.Looper.loop(Looper.java:123) 05-23 16:32:02.051: ERROR/AndroidRuntime(10742): at android.app.ActivityThread.main(ActivityThread.java:4595) 05-23 16:32:02.051: ERROR/AndroidRuntime(10742): at java.lang.reflect.Method.invokeNative(Native Method) 05-23 16:32:02.051: ERROR/AndroidRuntime(10742): at java.lang.reflect.Method.invoke(Method.java:521) 05-23 16:32:02.051: ERROR/AndroidRuntime(10742): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 05-23 16:32:02.051: ERROR/AndroidRuntime(10742): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 05-23 16:32:02.051: ERROR/AndroidRuntime(10742): at dalvik.system.NativeStart.main(Native Method) 05-23 16:32:02.051: ERROR/AndroidRuntime(10742): Caused by: java.lang.ClassCastException: android.view.View 05-23 16:32:02.051: ERROR/AndroidRuntime(10742): at sailmeter.gui.SailMeter.onCreate(SailMeter.java:51) 05-23 16:32:02.051: ERROR/AndroidRuntime(10742): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 05-23 16:32:02.051: ERROR/AndroidRuntime(10742): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544) 05-23 16:32:02.051: ERROR/AndroidRuntime(10742): ... 11 more Why cant i cast my custom view? I need it to be that type since it has a few extra methods in it that i want to access. Should i restructure it and have another class handle the logic, and then just having the view being a view? Thanks for any help.

    Read the article

  • android getAppWidgetIds failed, what wrong?

    - by bright
    I want to use following code to get a widget id, but getAppWidgetIds always return an empty array, the num is alway 0, what wrong? Thanks! public class test extends Activity implements OnTouchListener { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ..... AppWidgetManager mAppWidgetManager; AppWidgetHost mAppWidgetHost; mAppWidgetManager = AppWidgetManager.getInstance(this.getApplicationContext()); ComponentName THIS_APPWIDGET =new ComponentName("com.android.music", "com.android.music.MediaAppWidgetProvider"); int[] appWidgetId=mAppWidgetManager.getAppWidgetIds(THIS_APPWIDGET); int num=appWidgetId.length;

    Read the article

  • PopupWindow with GridView - Trouble with inflating view

    - by k_day
    I am having an issue while trying to use a GridView in a PopupWindow. On my Activity's onCreate method, I am inflating a gridview from xml as follows: LayoutInflater inflater = (LayoutInflater)this.getSystemService (Context.LAYOUT_INFLATER_SERVICE); final GridView popupview = (GridView) inflater.inflate (R.layout.gridviewpopup, null, false); popupview.setAdapter(new ImageAdapter(this)); would like this GridView to popup on a button click. Also inside of my activity's onCreate, I have: final Button addButton = (Button) findViewById(R.id.add); addButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { PopupWindow mwindow = new PopupWindow(popupview, 100, 100); mwindow.showAtLocation(findViewById(R.id.main), Gravity.CENTER, 100, 100); mwindow.setFocusable(true); } }); On button click, I am throwing a ClassCastException from GridView.onMeasure(int, int). Can anyone please explain to me what I am doing wrong?

    Read the article

  • Android Maps Back Button

    - by aaronr
    I'm developing an application that shows a path on a map, determined by a KML file. Specifically, in the MapActivity that is starting the map: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); MapView mapView = (MapView) findViewById(R.id.mapview); mapView.setBuiltInZoomControls(true); Uri uri = Uri.parse("geo:0,0?q=http://urltokml"); Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri); mapIntent.setData(uri); startActivity(Intent.createChooser(mapIntent, kmlFile)); finish(); } The map loads fine and after a few seconds the path described by the KML shows up. The problem is, when I press the "Back" button, it does not return to the previous screen but instead just hides the KML overlay. If the "Back" button is pressed again, it will return to the previous screen. Any ideas of how to solve this?

    Read the article

  • R cannot be resolved - android error

    - by MaurizioPz
    Hi, I just downloaded and installed the new android sdk. I wanted to create a simple application to test drive it. the widzard creates this code: package eu.mauriziopz.gps; import android.app.Activity; import android.os.Bundle; public class ggps extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } but ecplise give me this error R cannot be resolved on this line setContentView(R.layout.main); can any one explain me why? ps. I do have an xml file named main.xml under res/layout/

    Read the article

  • Android: Crashed when single contact is clicked

    - by Sean Tan
    My application is always crashed at this moment, guru here please help me to solved. Thanks.The situation now is as mentioned in title above. Hereby is my AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2009 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.contactmanager" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="10" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/> <uses-permission android:name="android.permission.WRITE_OWNER_DATA"/> <uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.CALL_PHONE"/> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.WRITE_CONTACTS" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.GET_ACCOUNTS"/> <application android:label="@string/app_name" android:icon="@drawable/icon" android:allowBackup="true"> <!-- --><activity android:name=".ContactManager" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="ContactAdder" android:label="@string/addContactTitle"> </activity> <activity android:name=".SingleListContact" android:label="Contact Person Details"> </activity> </application> </manifest> The SingleListContact.java package com.example.android.contactmanager; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.TextView; public class SingleListContact extends Activity{ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.single_list_contact_view); TextView txtContact = (TextView) findViewById(R.id.contactList); Intent i = getIntent(); // getting attached intent data String contact = i.getStringExtra("contact"); // displaying selected product name txtContact.setText(contact); } } My ContactManager.java as below /* * Copyright (C) 2009 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.android.contactmanager; import android.app.Activity; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.provider.ContactsContract; import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.ListView; import android.widget.SimpleCursorAdapter; import android.widget.TextView; public final class ContactManager extends Activity implements OnItemClickListener { public static final String TAG = "ContactManager"; private Button mAddAccountButton; private ListView mContactList; private boolean mShowInvisible; //public BooleanObservable ShowInvisible = new BooleanObservable(false); private CheckBox mShowInvisibleControl; /** * Called when the activity is first created. Responsible for initializing the UI. */ @Override public void onCreate(Bundle savedInstanceState) { Log.v(TAG, "Activity State: onCreate()"); super.onCreate(savedInstanceState); setContentView(R.layout.contact_manager); // Obtain handles to UI objects mAddAccountButton = (Button) findViewById(R.id.addContactButton); mContactList = (ListView) findViewById(R.id.contactList); mShowInvisibleControl = (CheckBox) findViewById(R.id.showInvisible); // Initialise class properties mShowInvisible = false; mShowInvisibleControl.setChecked(mShowInvisible); // Register handler for UI elements mAddAccountButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Log.d(TAG, "mAddAccountButton clicked"); launchContactAdder(); } }); mShowInvisibleControl.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { Log.d(TAG, "mShowInvisibleControl changed: " + isChecked); mShowInvisible = isChecked; populateContactList(); } }); mContactList = (ListView) findViewById(R.id.contactList); mContactList.setOnItemClickListener(this); // Populate the contact list populateContactList(); } /** * Populate the contact list based on account currently selected in the account spinner. */ private void populateContactList() { // Build adapter with contact entries Cursor cursor = getContacts(); String[] fields = new String[] { ContactsContract.Data.DISPLAY_NAME }; SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.contact_entry, cursor, fields, new int[] {R.id.contactEntryText}); mContactList.setAdapter(adapter); } /** * Obtains the contact list for the currently selected account. * * @return A cursor for for accessing the contact list. */ private Cursor getContacts() { // Run query Uri uri = ContactsContract.Contacts.CONTENT_URI; String[] projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME }; String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" + (mShowInvisible ? "0" : "1") + "'"; //String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" + (mShowInvisible.get() ? "0" : "1") + "'"; String[] selectionArgs = null; String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC"; return this.managedQuery(uri, projection, selection, selectionArgs, sortOrder); } /** * Launches the ContactAdder activity to add a new contact to the selected account. */ protected void launchContactAdder() { Intent i = new Intent(this, ContactAdder.class); startActivity(i); } public void onItemClick(AdapterView<?> l, View v, int position, long id) { Log.i("TAG", "You clicked item " + id + " at position " + position); // Here you start the intent to show the contact details // selected item TextView tv=(TextView)v.findViewById(R.id.contactList); String allcontactlist = tv.getText().toString(); // Launching new Activity on selecting single List Item Intent i = new Intent(getApplicationContext(), SingleListContact.class); // sending data to new activity i.putExtra("Contact Person", allcontactlist); startActivity(i); } } contact_entry.xml <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2009 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <ListView android:layout_width="wrap_content" android:id="@+id/contactList" android:layout_height="0dp" android:padding="10dp" android:textSize="200sp" android:layout_weight="10"/> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/showInvisible" android:text="@string/showInvisible"/> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/addContactButton" android:text="@string/addContactButtonLabel"/> </LinearLayout> Logcat result: 12-05 05:00:31.289: E/AndroidRuntime(642): FATAL EXCEPTION: main 12-05 05:00:31.289: E/AndroidRuntime(642): java.lang.NullPointerException 12-05 05:00:31.289: E/AndroidRuntime(642): at com.example.android.contactmanager.ContactManager.onItemClick(ContactManager.java:148) 12-05 05:00:31.289: E/AndroidRuntime(642): at android.widget.AdapterView.performItemClick(AdapterView.java:284) 12-05 05:00:31.289: E/AndroidRuntime(642): at android.widget.ListView.performItemClick(ListView.java:3513) 12-05 05:00:31.289: E/AndroidRuntime(642): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812) 12-05 05:00:31.289: E/AndroidRuntime(642): at android.os.Handler.handleCallback(Handler.java:587) 12-05 05:00:31.289: E/AndroidRuntime(642): at android.os.Handler.dispatchMessage(Handler.java:92) 12-05 05:00:31.289: E/AndroidRuntime(642): at android.os.Looper.loop(Looper.java:123) 12-05 05:00:31.289: E/AndroidRuntime(642): at android.app.ActivityThread.main(ActivityThread.java:3683) 12-05 05:00:31.289: E/AndroidRuntime(642): at java.lang.reflect.Method.invokeNative(Native Method) 12-05 05:00:31.289: E/AndroidRuntime(642): at java.lang.reflect.Method.invoke(Method.java:507) 12-05 05:00:31.289: E/AndroidRuntime(642): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 12-05 05:00:31.289: E/AndroidRuntime(642): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 12-05 05:00:31.289: E/AndroidRuntime(642): at dalvik.system.NativeStart.main(Native Method)

    Read the article

  • Android app in eclipse

    - by Colin
    Hello everybody, i've searched for days but cant find an answer, perhaps you guys can help. I'm creating an android app in eclipse, it all works just one thing is bugging me. this is my main.java: package com.test; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Toast; public class Main extends Activity implements OnClickListener { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Add Click listeners for all buttons View firstButton = findViewById(R.id.btn_rassen); firstButton.setOnClickListener(this); View secondButton = findViewById(R.id.button2); secondButton.setOnClickListener(this); } // Process the button click events @Override public void onClick(View v) { switch(v.getId()){ case R.id.btn_rassen: Intent j = new Intent(this, Webscreen.class); j.putExtra(com.test.Webscreen.URL, "http://www.google.com/"); startActivity(j); break; case R.id.button2: Intent k = new Intent(this, Webscreen.class); k.putExtra(com.test.Webscreen.URL, "http://notworkingurltotest.com"); startActivity(k); break; } } } now when it calls the webview.java the page called shows up but not the buttons i created in the layout xml page. does anybody have any idea why this is? your help is much appreciated! ohw this is my webscreen.java package com.test; import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.Window; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Toast; public class Webscreen extends Activity { public static final String URL = ""; private static final String TAG = "WebscreenClass"; private WebView webview; private ProgressDialog progressDialog; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.webscreen); this.getIntent().getExtras(); this.webview = (WebView) findViewById(R.string.webview); String turl = getIntent().getStringExtra(URL); Log.i(TAG, " URL = "+turl); WebView webview = new WebView(this); setContentView(webview); final Activity activity = this; webview.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } public void onLoadResource (WebView view, String url) { if (progressDialog == null) { progressDialog = new ProgressDialog(activity); progressDialog.setMessage("Bezig met laden..."); progressDialog.show(); } } public void onPageFinished(WebView view, String url) { if (progressDialog.isShowing()) { progressDialog.dismiss(); progressDialog = null; } } public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Intent myIntent = new Intent(); myIntent.setClassName("com.test", "com.test.Main"); startActivity(myIntent); Toast.makeText(activity, "Laden van onderdeel mislukt, probeer het later nog eens! ", Toast.LENGTH_LONG).show(); progressDialog.show(); } }); webview.loadUrl(turl); } } webscreen.xml layout: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <!-- <1> --> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/url" android:layout_height="wrap_content" android:layout_width="wrap_content" android:lines="1" android:layout_weight="1.0" android:hint="http://" android:visibility="visible" /> <Button android:id="@+id/go_button" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="go_button" /> </LinearLayout> <!-- <2> --> <WebView android:id="@string/webview" android:layout_width="fill_parent" android:layout_height="0dip" /> </LinearLayout>

    Read the article

  • NullPointerException when trying to connect to web service using kSoap method Android

    - by benjamin schultz
    My web service should be returning an integer, but every time i run the code i get the NullPointerException error. Any ideas or help would be very appreciated Here's my code: public class CGCountTest extends Activity { TextView testTV; private static final String NAMESPACE = "http://passport-america.com/webservices/"; private static final String URL = "http://localhost:11746/Service1.asmx"; private static final String SOAP_ACTION = "http://www.passport-america.com/webservices/getCGCount"; private static final String METHOD_NAME = "getCGCount"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.soap_test); SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); try { androidHttpTransport.call(SOAP_ACTION, envelope); java.lang.Integer result = (Integer)envelope.getResponse(); TextView testTV = (TextView)findViewById(R.id.testTV); result.toString(); testTV.setText(result); } catch(Exception e) { testTV.setText(e.getMessage()); } } here's the logcat 06-02 15:13:36.557: WARN/dalvikvm(326): threadid=3: thread exiting with uncaught exception (group=0x4001aa28) 06-02 15:13:36.557: ERROR/AndroidRuntime(326): Uncaught handler: thread main exiting due to uncaught exception 06-02 15:13:36.876: ERROR/AndroidRuntime(326): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pa.passammain/com.pa.passammain.CGCountTest}: java.lang.NullPointerException 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at android.app.ActivityThread.access$2100(ActivityThread.java:116) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at android.os.Handler.dispatchMessage(Handler.java:99) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at android.os.Looper.loop(Looper.java:123) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at android.app.ActivityThread.main(ActivityThread.java:4203) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at java.lang.reflect.Method.invokeNative(Native Method) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at java.lang.reflect.Method.invoke(Method.java:521) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at dalvik.system.NativeStart.main(Native Method) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): Caused by: java.lang.NullPointerException 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at com.pa.passammain.CGCountTest.onCreate(CGCountTest.java:46) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364) 06-02 15:13:36.876: ERROR/AndroidRuntime(326): ... 11 more i think my url string may be the problem, but i've tried using my ip with no luck

    Read the article

  • Why / When / How is this Android serviceBinder resetting to null?

    - by GaZ
    I've written a ListActivity for Android 2.1 which is used to display a list of event categories. As the user selects a category, the program calls a web service to retrieve a list of sub-events. For example, a top level event might be "soccer" and when the user selects this the web service would return various soccer associations (e.g. "english", "french", "german", etc.) and display them in a new list. The following code seems to work occasionally, however sometimes the call to the service (in EventsListTask) fails because the serviceBinder is null. How/Why does this happen? public class EventListsActivity extends ListActivity { private static final String EVENT_ID = "EventId"; private List<ListItem> eventList; private ArrayAdapter<ListItem> listItemArrayAdapter; private static final int LOADING_DIALOG = 1; private EventsListTask eventsListTask = null; private BFService serviceBinder; private ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName componentName, IBinder iBinder) { Log.i("EventListsActivity", "service connected"); serviceBinder = ((BFService.BFBinder)iBinder).getService(); } public void onServiceDisconnected(ComponentName componentName) { Log.i("EventListsActivity", "service disconnected"); serviceBinder = null; } }; @Override public void onCreate(Bundle savedInstanceState) { Log.i("EventListsActivity", "onCreate"); super.onCreate(savedInstanceState); setContentView(R.layout.list); eventList = new ArrayList<ListItem>(); listItemArrayAdapter = new ArrayAdapter<ListItem>(this, R.layout.row, eventList); setListAdapter(listItemArrayAdapter); Intent bindIntent = new Intent(this, BFService.class); bindService(bindIntent, mConnection, Context.BIND_AUTO_CREATE); int eventId = getIntent().getIntExtra(EVENT_ID, -1); if (eventsListTask == null || eventsListTask.getStatus() == AsyncTask.Status.FINISHED) { eventsListTask = new EventsListTask(); eventsListTask.execute(eventId); } } @Override protected void onDestroy() { Log.i("EventListsActivity", "destroyed"); super.onDestroy(); unbindService(mConnection); } @Override protected void onListItemClick(ListView listView, View view, int position, long id) { super.onListItemClick(listView, view, position, id); ListItem selectedItem = (ListItem) listView.getAdapter().getItem(position); Intent intent; if (selectedItem.getMarketType() != null) { intent = new Intent(this, MarketActivity.class); intent.putExtra(EVENT_ID, selectedItem.getId()); startActivityIfNeeded(intent, -1); } else if (selectedItem.getId() != -1) { intent = new Intent(this, EventListsActivity.class); intent.putExtra(EVENT_ID, selectedItem.getId()); startActivityIfNeeded(intent, -1); } else { Log.e("EventListsActivity", "unexpected item selected!"); } } @Override protected Dialog onCreateDialog(int id) { switch (id) { case (LOADING_DIALOG) : AlertDialog.Builder loadingDialog = new AlertDialog.Builder(this); loadingDialog.setTitle("Please Wait..."); loadingDialog.setMessage("Communicating with remote service."); return loadingDialog.create(); } return null; } private class EventsListTask extends AsyncTask<Integer, Void, LoginStatusEnum> { @Override protected void onPreExecute() { showDialog(LOADING_DIALOG); } @Override protected void onPostExecute(LoginStatusEnum loginStatusEnum) { dismissDialog(LOADING_DIALOG); if (loginStatusEnum != null) { switch (loginStatusEnum) { case OK: for (ListItem item : eventList) { listItemArrayAdapter.add(item); } listItemArrayAdapter.notifyDataSetChanged(); break; } } } @Override protected LoginStatusEnum doInBackground(Integer... params) { LoginStatusEnum result = LoginStatusEnum.OK; Integer eventId = params[0]; if (serviceBinder != null) { try { if (eventId == null || eventId == -1) { eventList = serviceBinder.getActiveEventTypes(); } else { eventList = serviceBinder.getEvents(eventId); } } catch (WebServiceException wse) { result = LoginStatusEnum.valueOf(wse.getMessage()); } } else { Log.e("EventListsActivity", "serviceBinder is null!"); } return result; } } } EDIT: The serviceBinder appears to be set to null when I reach the bottom of a list, when I change the target intent to go to a different activity: intent = new Intent(this, MarketActivity.class); intent.putExtra(EVENT_ID, selectedItem.getId()); startActivity(intent); This new activity also uses the same background service (binds in the same way, etc.). Is there anything I need to watch out for when doing this? Am I calling the target intent incorrectly? EDIT2: Here's the output from LogCat when I start the activity which calls the service (this time the service failed straight away!): 04-02 07:02:49.147: INFO/ActivityManager(61): Starting activity: Intent { cmp=net.foobar.activity/.EventListsActivity } 04-02 07:02:49.257: INFO/EventListsActivity(353): onCreate 04-02 07:02:49.426: INFO/EventListsActivity(353): service connected 04-02 07:02:49.437: ERROR/EventListsActivity(353): serviceBinder is null!

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >