Search Results

Search found 13533 results on 542 pages for 'android activity'.

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

  • JavaNullPointerException/Layout Error when working with lists and ListView on Android

    - by psyhclo
    Hey, I'm trying to implement a ListView on Android, which will print the data retrieved from the SQLite Database. So I want to retrieve a lot of columns from the table and add this to a list, so I will print this list as a ListView. For this I created a method that will select all the columns from the table in a separate class, and I will print the ListView in a ListActivity. I want to retrieve 6 columns of the table, which is represented by the ids 2, 4, 5, 6, 7, 9. But it shows a lot of errors: 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): FATAL EXCEPTION: main 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): java.lang.NullPointerException 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:355) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.AbsListView.obtainView(AbsListView.java:1418) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.ListView.makeAndAddView(ListView.java:1745) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.ListView.fillDown(ListView.java:670) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.ListView.fillFromTop(ListView.java:727) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.ListView.layoutChildren(ListView.java:1598) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.AbsListView.onLayout(AbsListView.java:1248) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.View.layout(View.java:7175) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.FrameLayout.onLayout(FrameLayout.java:338) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.View.layout(View.java:7175) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.FrameLayout.onLayout(FrameLayout.java:338) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.View.layout(View.java:7175) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.FrameLayout.onLayout(FrameLayout.java:338) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.View.layout(View.java:7175) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.View.layout(View.java:7175) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.FrameLayout.onLayout(FrameLayout.java:338) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.View.layout(View.java:7175) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.FrameLayout.onLayout(FrameLayout.java:338) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.View.layout(View.java:7175) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.View.layout(View.java:7175) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.widget.FrameLayout.onLayout(FrameLayout.java:338) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.View.layout(View.java:7175) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.ViewRoot.performTraversals(ViewRoot.java:1140) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.os.Handler.dispatchMessage(Handler.java:99) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.os.Looper.loop(Looper.java:123) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at android.app.ActivityThread.main(ActivityThread.java:3647) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at java.lang.reflect.Method.invokeNative(Native Method) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at java.lang.reflect.Method.invoke(Method.java:507) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 12-24 19:19:04.066: ERROR/AndroidRuntime(22630): at dalvik.system.NativeStart.main(Native Method) Here is the code of the method that select the data. public List<String> selectAll() { List<String> list1 = new ArrayList<String>(); List<String> list2 = new ArrayList<String>(); List<String> list3 = new ArrayList<String>(); List<String> list4 = new ArrayList<String>(); List<String> list5 = new ArrayList<String>(); List<String> list6 = new ArrayList<String>(); Cursor cursor = this.db.query(TABLE_NAME, null, null, null, null, null, "duration desc"); if (cursor.moveToFirst()) { do { list1.add(cursor.getString(2)); list2.add(cursor.getString(4)); list3.add(cursor.getString(5)); list4.add(cursor.getString(6)); list5.add(cursor.getString(7)); list6.add(cursor.getString(9)); list1.addAll(list2); list1.addAll(list3); list1.addAll(list4); list1.addAll(list5); list1.addAll(list6); } while (cursor.moveToNext()); Log.i(TAG, "After cursor.moveToNext()"); } if (cursor != null && !cursor.isClosed()) { cursor.close(); } Log.i(TAG, "Before selectAll returnment"); return list1; } And here is the code of the ListActivity class: public class RatedCalls extends ListActivity { private static final String LOG_TAG = "RatedCallsActivity"; private CallDataHelper cdh; StringBuilder sb = new StringBuilder(); OpenHelper openHelper = new OpenHelper(RatedCalls.this); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(LOG_TAG, "calling from onCreate()"); cdh = new CallDataHelper(this); Log.i(LOG_TAG, "--->>> before calling the service"); startService(new Intent(this, RatedCallsService.class)); Log.i(LOG_TAG, "Service called."); Log.i(LOG_TAG, "--->>> after calling the service"); fillList(); } public void fillList() { List<String> ratedCalls = this.cdh.selectAll(); setListAdapter(new ArrayAdapter<String>(this, R.layout.listitem, ratedCalls)); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // When clicked, show a toast with the TextView text Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show(); } }); } }

    Read the article

  • onListItemClick and CheckedTextView not respoding

    - by rayman
    Hi, i got ListActivity, each item has 2 textviews image and CheckedTextView. i am trying to implement simple multichoiselist... i have two problems: 1. @Override protected void onListItemClick(android.widget.ListView l, View v, int position, long id) { ... } doesnt respond at all ive tried it with the debugger and when i press on any list item it doesnt stop there. and ive tried all kind of things (like focusable:false) two:. i cant toggle the CheckedTextView anyhow. here is my xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="100sp" android:focusable="false" android:focusableInTouchMode="false"> android:padding="6dip"> <ImageView android:layout_width="wrap_content" android:layout_height="fill_parent" android:src="@drawable/icon" android:id="@drawable/icon" android:layout_marginLeft="6dip" android:focusable="false" android:focusableInTouchMode="false"> </ImageView> <LinearLayout android:id="@+id/LinearLayout01" android:orientation="vertical" android:layout_width="1sp" android:layout_height="fill_parent" android:layout_weight="1" android:focusable="false" android:focusableInTouchMode="false"> <TextView android:id="@+id/toptext" android:layout_weight="1" android:gravity="center_vertical" android:text="OrderNum" android:singleLine="true" android:layout_height="0dp" android:layout_width="wrap_content" android:focusable="false" android:focusableInTouchMode="false"> </TextView> <TextView android:id="@+id/bottomtext" android:layout_height="wrap_content" android:layout_width="wrap_content" android:focusable="false" android:focusableInTouchMode="false" android:text="TweetMsg"> </TextView> <TextView android:id="@+id/twittLocation" android:layout_weight="1" android:text="location" android:singleLine="true" android:layout_width="fill_parent" android:layout_height="0dip" android:focusable="false" android:focusableInTouchMode="false"> </TextView> <TextView android:layout_weight="1" android:id="@+id/twittLocationlink" android:text="locationlink" android:gravity="fill_horizontal" android:layout_width="fill_parent" android:layout_height="0dip" android:focusable="false" android:focusableInTouchMode="false"> </TextView> </LinearLayout> <CheckedTextView android:id="@android:id/text1" android:text="Delete" android:layout_width="wrap_content" android:layout_marginRight="2dp" android:layout_height="fill_parent" android:checkMark="?android:attr/listChoiceIndicatorMultiple" android:focusable="false"></CheckedTextView> </LinearLayout> any idea what's the problem? thanks.

    Read the article

  • Custom listview entry works in JB not in Gingerbread

    - by Andy
    I have a ListFragment with a custom ArrayAdapter where I am overiding getView() to provide a custom View for the list item. private class DirListAdaptor extends ArrayAdapter<DirItem> { @Override public View getView(int position, View convertView, ViewGroup parent) { View aView = convertView; if (aView == null) { LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); // TODO: can we not access textViewResourceId? aView = vi.inflate(R.layout.dir_list_entry, parent, false); } etc... Here is the dir_list_entry.xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="?android:attr/listPreferredItemHeight" android:paddingLeft="?android:attr/listPreferredItemPaddingLeft" android:paddingRight="?android:attr/listPreferredItemPaddingRight"> <ImageView android:id="@+id/dir_list_icon" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignParentTop="true" android:layout_alignParentBottom="true" android:layout_marginRight="6dp" android:src="@drawable/ic_launcher" /> <TextView android:id="@+id/dir_list_details" android:textAppearance="?android:attr/textAppearanceListItem" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_toRightOf="@id/dir_list_icon" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:singleLine="true" android:ellipsize="marquee" android:textSize="12sp" android:text="Details" /> <TextView android:id="@+id/dir_list_filename" android:textAppearance="?android:attr/textAppearanceListItem" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_toRightOf="@id/dir_list_icon" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_above="@id/dir_list_details" android:layout_alignWithParentIfMissing="true" android:gravity="center_vertical" android:textSize="14sp" android:text="Filename"/> </RelativeLayout> The bizarre thing is this works fine on Android 4.1 emulator, but I get the following error on Android 2.3: 10-01 15:07:59.594: ERROR/AndroidRuntime(1003): FATAL EXCEPTION: main android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout at android.view.LayoutInflater.createView(LayoutInflater.java:518) at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568) at android.view.LayoutInflater.inflate(LayoutInflater.java:386) at android.view.LayoutInflater.inflate(LayoutInflater.java:320) at com.eveps.evepsdroid.ui.PhotoBrowserListFragment$DirListAdaptor.getView(PhotoBrowserListFragment.java:104) at android.widget.AbsListView.obtainView(AbsListView.java:1430) at android.widget.ListView.makeAndAddView(ListView.java:1745) at android.widget.ListView.fillDown(ListView.java:670) at android.widget.ListView.fillFromTop(ListView.java:727) at android.widget.ListView.layoutChildren(ListView.java:1598) at android.widget.AbsListView.onLayout(AbsListView.java:1260) at android.view.View.layout(View.java:7175) at android.widget.FrameLayout.onLayout(FrameLayout.java:338) at android.view.View.layout(View.java:7175) at android.widget.FrameLayout.onLayout(FrameLayout.java:338) at android.view.View.layout(View.java:7175) at android.widget.FrameLayout.onLayout(FrameLayout.java:338) at android.view.View.layout(View.java:7175) at android.widget.FrameLayout.onLayout(FrameLayout.java:338) at android.view.View.layout(View.java:7175) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254) at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1243) at android.widget.LinearLayout.onLayout(LinearLayout.java:1049) at android.view.View.layout(View.java:7175) at android.widget.FrameLayout.onLayout(FrameLayout.java:338) at android.view.View.layout(View.java:7175) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130) at android.widget.LinearLayout.onLayout(LinearLayout.java:1047) at android.view.View.layout(View.java:7175) at android.widget.FrameLayout.onLayout(FrameLayout.java:338) at android.view.View.layout(View.java:7175) at android.view.ViewRoot.performTraversals(ViewRoot.java:1140) at android.view.ViewRoot.handleMessage(ViewRoot.java:1859) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:3683) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.constructNative(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:415) at android.view.LayoutInflater.createView(LayoutInflater.java:505) ... 42 more Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x2 at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463) at android.view.View.<init>(View.java:1957) at android.view.View.<init>(View.java:1899) at android.view.ViewGroup.<init>(ViewGroup.java:286) at android.widget.RelativeLayout.<init>(RelativeLayout.java:173) ... 45 more I'm using the Android Support library for fragment support obviously. Seems to be a problem inflating the custom list view entry, something to do with a dimension - but why does it work on JellyBean? Has something changed in this area?

    Read the article

  • Binary XML file <line 20>: Error inflating class <Unknown>

    - by user2750644
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="top|left|right" android:background="@drawable/bg" tools:context=".MainActivity" > <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="50dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:src="@drawable/top_red_bar" android:layout_alignParentLeft="true" android:paddingLeft="0dp" android:scaleType="centerCrop" /> <ImageView android:id="@+id/imageView2" android:layout_width="wrap_content" android:layout_height="45dp" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_alignTop="@+id/imageView1" android:layout_centerHorizontal="true" android:src="@drawable/job_bar" /> <ImageView android:id="@+id/imageView3" android:layout_width="238dp" android:layout_height="50dp" android:layout_below="@+id/imageView1" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:layout_marginTop="123dp" android:src="@drawable/button" android:alpha="0.85" android:onClick="myhandler"/> <ImageView android:id="@+id/imageView4" android:layout_width="wrap_content" android:layout_height="50dp" android:layout_alignParentLeft="true" android:layout_below="@+id/imageView3" android:layout_marginTop="24dp" android:src="@drawable/button" android:alpha="0.85"/> <ImageView android:id="@+id/imageView5" android:layout_width="35dp" android:layout_height="45dp" android:layout_above="@+id/imageView4" android:layout_alignLeft="@+id/imageView3" android:layout_marginLeft="21dp" android:src="@drawable/employer" /> <ImageView android:id="@+id/imageView6" android:layout_width="50dp" android:layout_height="50dp" android:layout_alignLeft="@+id/imageView5" android:layout_alignTop="@+id/imageView4" android:src="@drawable/jobseekers" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/imageView5" android:layout_centerHorizontal="true" android:layout_marginLeft="18dp" android:layout_toRightOf="@+id/imageView6" android:text="Employer" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="#ffffff" android:textStyle="bold" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_alignTop="@+id/imageView4" android:text="Job Seekers" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="#ffffff" android:textStyle="bold" /> </RelativeLayout> My app gets crashed with error statement Binary XML file <line 20>: Error inflating class <Unknown>. Why does this happen?? Could anyone fix this? And interestingly, when I remove all code except background, it works!!!

    Read the article

  • Part of my layout goes upward with keyboard

    - by Burak Dede
    My android app have a layout like this when i open keyboard two imageview at the bottom of the page shows up over the keyboard , i couldnt see the problem why it goes upward with the keyboard can you help me about this ? <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:id="@+id/searchLinear" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/upperbackground"> <EditText android:id="@+id/searchBox" android:layout_alignParentTop="true" android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="true" android:layout_margin="12dip" android:paddingLeft="35dip" android:textSize="15sp" android:background="@drawable/search_bar"/> </LinearLayout> <LinearLayout android:id="@+id/searchButtons" android:layout_below="@id/searchLinear" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical|center_horizontal" android:background="@color/upperbackground"> <ImageView android:id="@+id/btnSukela" android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="true" android:focusable="true" android:onClick="sukelaClickEvent" android:paddingRight="8dip" android:paddingBottom="5dip" android:src="@drawable/sukela"/> <ImageView android:id="@+id/btnSearch" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/btnSukela" android:clickable="true" android:focusable="true" android:onClick="searchEntryClickEvent" android:paddingLeft="8dip" android:paddingBottom="5dip" android:src="@drawable/search"/> </LinearLayout> <RelativeLayout android:id="@+id/bottomLinear" android:layout_alignParentBottom="true" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical|center_horizontal" android:background="@drawable/bottom_back"> <ImageView android:id="@+id/btnToday" android:src="@drawable/today" android:background="@color/bottombackground" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/bottomLinear" android:layout_marginBottom="19dip" android:layout_centerVertical="true" android:clickable="true" android:focusable="true" android:onClick="todayClickEvent"/> <ImageView android:id="@+id/btnPopular" android:src="@drawable/popular" android:background="@color/bottombackground" android:layout_toRightOf="@+id/btnToday" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:clickable="true" android:focusable="true" android:onClick="popularClickEvent"/> </RelativeLayout> <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@+id/searchButtons" android:layout_above="@+id/bottomLinear" android:background="@color/background"> <ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="wrap_content"/> </RelativeLayout> </RelativeLayout>

    Read the article

  • Example: Communication between Activity and Service using Messaging

    - by Lance Lefebure
    I couldn't find any examples of how to send messages between an activity and a service, and spent far too many hours figuring this out. Here is an example project for others to reference. This example allows you to start or stop a service directly, and separately bind/unbind from the service. When the service is running, it increments a number at 10Hz. If the activity is bound to the service, it will display the current value. Data is transferred as an Integer and as a String so you can see how to do that two different ways. There are also buttons in the activity to send messages to the service (changes the increment-by value). Screenshot: AndroidManifest.xml: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.exampleservice" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <service android:name=".MyService"></service> </application> <uses-sdk android:minSdkVersion="8" /> </manifest> res\values\strings.xml: <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">ExampleService</string> <string name="service_started">Example Service started</string> <string name="service_label">Example Service Label</string> </resources> res\layout\main.xml: <?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" > <RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:id="@+id/btnStart" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Start Service"></Button> <Button android:id="@+id/btnStop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Stop Service" android:layout_alignParentRight="true"></Button> </RelativeLayout> <RelativeLayout android:id="@+id/RelativeLayout02" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:id="@+id/btnBind" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Bind to Service"></Button> <Button android:id="@+id/btnUnbind" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Unbind from Service" android:layout_alignParentRight="true"></Button> </RelativeLayout> <TextView android:id="@+id/textStatus" android:textSize="24sp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Status Goes Here" /> <TextView android:id="@+id/textIntValue" android:textSize="24sp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Integer Value Goes Here" /> <TextView android:id="@+id/textStrValue" android:textSize="24sp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="String Value Goes Here" /> <RelativeLayout android:id="@+id/RelativeLayout03" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:id="@+id/btnUpby1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Increment by 1"></Button> <Button android:id="@+id/btnUpby10" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Increment by 10" android:layout_alignParentRight="true"></Button> </RelativeLayout> </LinearLayout> src\com.exampleservice\MainActivity.java: package com.exampleservice; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.os.Messenger; import android.os.RemoteException; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class MainActivity extends Activity { Button btnStart, btnStop, btnBind, btnUnbind, btnUpby1, btnUpby10; TextView textStatus, textIntValue, textStrValue; Messenger mService = null; boolean mIsBound; final Messenger mMessenger = new Messenger(new IncomingHandler()); class IncomingHandler extends Handler { @Override public void handleMessage(Message msg) { switch (msg.what) { case MyService.MSG_SET_INT_VALUE: textIntValue.setText("Int Message: " + msg.arg1); break; case MyService.MSG_SET_STRING_VALUE: String str1 = msg.getData().getString("str1"); textStrValue.setText("Str Message: " + str1); break; default: super.handleMessage(msg); } } } private ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { mService = new Messenger(service); textStatus.setText("Attached."); try { Message msg = Message.obtain(null, MyService.MSG_REGISTER_CLIENT); msg.replyTo = mMessenger; mService.send(msg); } catch (RemoteException e) { // In this case the service has crashed before we could even do anything with it } } public void onServiceDisconnected(ComponentName className) { // This is called when the connection with the service has been unexpectedly disconnected - process crashed. mService = null; textStatus.setText("Disconnected."); } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btnStart = (Button)findViewById(R.id.btnStart); btnStop = (Button)findViewById(R.id.btnStop); btnBind = (Button)findViewById(R.id.btnBind); btnUnbind = (Button)findViewById(R.id.btnUnbind); textStatus = (TextView)findViewById(R.id.textStatus); textIntValue = (TextView)findViewById(R.id.textIntValue); textStrValue = (TextView)findViewById(R.id.textStrValue); btnUpby1 = (Button)findViewById(R.id.btnUpby1); btnUpby10 = (Button)findViewById(R.id.btnUpby10); btnStart.setOnClickListener(btnStartListener); btnStop.setOnClickListener(btnStopListener); btnBind.setOnClickListener(btnBindListener); btnUnbind.setOnClickListener(btnUnbindListener); btnUpby1.setOnClickListener(btnUpby1Listener); btnUpby10.setOnClickListener(btnUpby10Listener); restoreMe(savedInstanceState); CheckIfServiceIsRunning(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putString("textStatus", textStatus.getText().toString()); outState.putString("textIntValue", textIntValue.getText().toString()); outState.putString("textStrValue", textStrValue.getText().toString()); } private void restoreMe(Bundle state) { if (state!=null) { textStatus.setText(state.getString("textStatus")); textIntValue.setText(state.getString("textIntValue")); textStrValue.setText(state.getString("textStrValue")); } } private void CheckIfServiceIsRunning() { //If the service is running when the activity starts, we want to automatically bind to it. if (MyService.isRunning()) { doBindService(); } } private OnClickListener btnStartListener = new OnClickListener() { public void onClick(View v){ startService(new Intent(MainActivity.this, MyService.class)); } }; private OnClickListener btnStopListener = new OnClickListener() { public void onClick(View v){ doUnbindService(); stopService(new Intent(MainActivity.this, MyService.class)); } }; private OnClickListener btnBindListener = new OnClickListener() { public void onClick(View v){ doBindService(); } }; private OnClickListener btnUnbindListener = new OnClickListener() { public void onClick(View v){ doUnbindService(); } }; private OnClickListener btnUpby1Listener = new OnClickListener() { public void onClick(View v){ sendMessageToService(1); } }; private OnClickListener btnUpby10Listener = new OnClickListener() { public void onClick(View v){ sendMessageToService(10); } }; private void sendMessageToService(int intvaluetosend) { if (mIsBound) { if (mService != null) { try { Message msg = Message.obtain(null, MyService.MSG_SET_INT_VALUE, intvaluetosend, 0); msg.replyTo = mMessenger; mService.send(msg); } catch (RemoteException e) { } } } } void doBindService() { bindService(new Intent(this, MyService.class), mConnection, Context.BIND_AUTO_CREATE); mIsBound = true; textStatus.setText("Binding."); } void doUnbindService() { if (mIsBound) { // If we have received the service, and hence registered with it, then now is the time to unregister. if (mService != null) { try { Message msg = Message.obtain(null, MyService.MSG_UNREGISTER_CLIENT); msg.replyTo = mMessenger; mService.send(msg); } catch (RemoteException e) { // There is nothing special we need to do if the service has crashed. } } // Detach our existing connection. unbindService(mConnection); mIsBound = false; textStatus.setText("Unbinding."); } } @Override protected void onDestroy() { super.onDestroy(); try { doUnbindService(); } catch (Throwable t) { Log.e("MainActivity", "Failed to unbind from the service", t); } } } src\com.exampleservice\MyService.java: package com.exampleservice; import java.util.ArrayList; import java.util.Timer; import java.util.TimerTask; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.os.Messenger; import android.os.RemoteException; import android.util.Log; public class MyService extends Service { private NotificationManager nm; private Timer timer = new Timer(); private int counter = 0, incrementby = 1; private static boolean isRunning = false; ArrayList<Messenger> mClients = new ArrayList<Messenger>(); // Keeps track of all current registered clients. int mValue = 0; // Holds last value set by a client. static final int MSG_REGISTER_CLIENT = 1; static final int MSG_UNREGISTER_CLIENT = 2; static final int MSG_SET_INT_VALUE = 3; static final int MSG_SET_STRING_VALUE = 4; final Messenger mMessenger = new Messenger(new IncomingHandler()); // Target we publish for clients to send messages to IncomingHandler. @Override public IBinder onBind(Intent intent) { return mMessenger.getBinder(); } class IncomingHandler extends Handler { // Handler of incoming messages from clients. @Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_REGISTER_CLIENT: mClients.add(msg.replyTo); break; case MSG_UNREGISTER_CLIENT: mClients.remove(msg.replyTo); break; case MSG_SET_INT_VALUE: incrementby = msg.arg1; break; default: super.handleMessage(msg); } } } private void sendMessageToUI(int intvaluetosend) { for (int i=mClients.size()-1; i>=0; i--) { try { // Send data as an Integer mClients.get(i).send(Message.obtain(null, MSG_SET_INT_VALUE, intvaluetosend, 0)); //Send data as a String Bundle b = new Bundle(); b.putString("str1", "ab" + intvaluetosend + "cd"); Message msg = Message.obtain(null, MSG_SET_STRING_VALUE); msg.setData(b); mClients.get(i).send(msg); } catch (RemoteException e) { // The client is dead. Remove it from the list; we are going through the list from back to front so this is safe to do inside the loop. mClients.remove(i); } } } @Override public void onCreate() { super.onCreate(); Log.i("MyService", "Service Started."); showNotification(); timer.scheduleAtFixedRate(new TimerTask(){ public void run() {onTimerTick();}}, 0, 100L); isRunning = true; } private void showNotification() { nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); // In this sample, we'll use the same text for the ticker and the expanded notification CharSequence text = getText(R.string.service_started); // Set the icon, scrolling text and timestamp Notification notification = new Notification(R.drawable.icon, text, System.currentTimeMillis()); // The PendingIntent to launch our activity if the user selects this notification PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); // Set the info for the views that show in the notification panel. notification.setLatestEventInfo(this, getText(R.string.service_label), text, contentIntent); // Send the notification. // We use a layout id because it is a unique number. We use it later to cancel. nm.notify(R.string.service_started, notification); } @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i("MyService", "Received start id " + startId + ": " + intent); return START_STICKY; // run until explicitly stopped. } public static boolean isRunning() { return isRunning; } private void onTimerTick() { Log.i("TimerTick", "Timer doing work." + counter); try { counter += incrementby; sendMessageToUI(counter); } catch (Throwable t) { //you should always ultimately catch all exceptions in timer tasks. Log.e("TimerTick", "Timer Tick Failed.", t); } } @Override public void onDestroy() { super.onDestroy(); if (timer != null) {timer.cancel();} counter=0; nm.cancel(R.string.service_started); // Cancel the persistent notification. Log.i("MyService", "Service Stopped."); isRunning = false; } }

    Read the article

  • How to create sliding drawer in both sides opposite to one another?

    - by janmejoy
    I have added the code that working for right to left sliding perfectly but i want sliding from left to right also so check the layout and help me out.Here i have mentioned the layout properly for right to left ,Is it possible to get the Slider window in both sides i mean left and right horizontally... <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg" android:orientation="vertical" > <Button android:id="@+id/ship" android:layout_width="186dp" android:layout_height="23dp" android:layout_marginTop="49dp" android:background="@drawable/signup" android:text="Shipping Calculator" android:textColor="#ffffffff" android:layout_gravity="center" android:textStyle="bold" /> </LinearLayout> <SlidingDrawer android:id="@+id/drawer" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:handle="@+id/handle" android:content="@+id/content"> <ImageView android:id="@+id/handle" android:layout_width="wrap_content" android:layout_height="fill_parent" android:src="@drawable/tag"/> <LinearLayout android:id="@+id/content" android:layout_width="wrap_content" android:layout_height="fill_parent" android:background="@drawable/slidimage" android:orientation="vertical" android:padding="10dp" > <TextView android:id="@+id/text1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="15dp" android:layout_marginLeft="51dp" android:text="SIGN-UP" android:textColor="#000000" android:textSize="28dp" android:textStyle="bold" /> </LinearLayout> </SlidingDrawer> <SlidingDrawer android:id="@+id/drawers" android:layout_width="match_parent" android:layout_height="match_parent" android:handle="@+id/handles" android:layout_gravity="left" android:scrollX="100dp" android:orientation="horizontal" android:content="@+id/contents"> <ImageView android:id="@+id/handles" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_gravity="left" android:src="@drawable/tag"/> <LinearLayout android:id="@+id/contents" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_gravity="left" android:background="@drawable/slidimage" android:orientation="vertical" android:padding="10dp" > <TextView android:id="@+id/text1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="15dp" android:layout_marginLeft="51dp" android:text="SIGN-UP" android:textColor="#000000" android:textSize="28dp" android:textStyle="bold" /> </LinearLayout> </SlidingDrawer> </FrameLayout>

    Read the article

  • Example: Communication between Activity and Service using Messaging

    - by Lance Lefebure
    I couldn't find any examples of how to send messages between an activity and a service, and spent far too many hours figuring this out. Here is an example project for others to reference. This example allows you to start or stop a service directly, and separately bind/unbind from the service. When the service is running, it increments a number at 10Hz. If the activity is bound to the service, it will display the current value. Data is transferred as an Integer and as a String so you can see how to do that two different ways. There are also buttons in the activity to send messages to the service (changes the increment-by value). Screenshot: AndroidManifest.xml: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.exampleservice" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <service android:name=".MyService"></service> </application> <uses-sdk android:minSdkVersion="8" /> </manifest> res\values\strings.xml: <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">ExampleService</string> <string name="service_started">Example Service started</string> <string name="service_label">Example Service Label</string> </resources> res\layout\main.xml: <?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" > <RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:id="@+id/btnStart" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Start Service"></Button> <Button android:id="@+id/btnStop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Stop Service" android:layout_alignParentRight="true"></Button> </RelativeLayout> <RelativeLayout android:id="@+id/RelativeLayout02" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:id="@+id/btnBind" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Bind to Service"></Button> <Button android:id="@+id/btnUnbind" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Unbind from Service" android:layout_alignParentRight="true"></Button> </RelativeLayout> <TextView android:id="@+id/textStatus" android:textSize="24sp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Status Goes Here" /> <TextView android:id="@+id/textIntValue" android:textSize="24sp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Integer Value Goes Here" /> <TextView android:id="@+id/textStrValue" android:textSize="24sp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="String Value Goes Here" /> <RelativeLayout android:id="@+id/RelativeLayout03" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:id="@+id/btnUpby1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Increment by 1"></Button> <Button android:id="@+id/btnUpby10" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Increment by 10" android:layout_alignParentRight="true"></Button> </RelativeLayout> </LinearLayout> src\com.exampleservice\MainActivity.java: package com.exampleservice; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.os.Messenger; import android.os.RemoteException; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class MainActivity extends Activity { Button btnStart, btnStop, btnBind, btnUnbind, btnUpby1, btnUpby10; TextView textStatus, textIntValue, textStrValue; Messenger mService = null; boolean mIsBound; final Messenger mMessenger = new Messenger(new IncomingHandler()); class IncomingHandler extends Handler { @Override public void handleMessage(Message msg) { switch (msg.what) { case MyService.MSG_SET_INT_VALUE: textIntValue.setText("Int Message: " + msg.arg1); break; case MyService.MSG_SET_STRING_VALUE: String str1 = msg.getData().getString("str1"); textStrValue.setText("Str Message: " + str1); break; default: super.handleMessage(msg); } } } private ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { mService = new Messenger(service); textStatus.setText("Attached."); try { Message msg = Message.obtain(null, MyService.MSG_REGISTER_CLIENT); msg.replyTo = mMessenger; mService.send(msg); } catch (RemoteException e) { // In this case the service has crashed before we could even do anything with it } } public void onServiceDisconnected(ComponentName className) { // This is called when the connection with the service has been unexpectedly disconnected - process crashed. mService = null; textStatus.setText("Disconnected."); } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btnStart = (Button)findViewById(R.id.btnStart); btnStop = (Button)findViewById(R.id.btnStop); btnBind = (Button)findViewById(R.id.btnBind); btnUnbind = (Button)findViewById(R.id.btnUnbind); textStatus = (TextView)findViewById(R.id.textStatus); textIntValue = (TextView)findViewById(R.id.textIntValue); textStrValue = (TextView)findViewById(R.id.textStrValue); btnUpby1 = (Button)findViewById(R.id.btnUpby1); btnUpby10 = (Button)findViewById(R.id.btnUpby10); btnStart.setOnClickListener(btnStartListener); btnStop.setOnClickListener(btnStopListener); btnBind.setOnClickListener(btnBindListener); btnUnbind.setOnClickListener(btnUnbindListener); btnUpby1.setOnClickListener(btnUpby1Listener); btnUpby10.setOnClickListener(btnUpby10Listener); restoreMe(savedInstanceState); CheckIfServiceIsRunning(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putString("textStatus", textStatus.getText().toString()); outState.putString("textIntValue", textIntValue.getText().toString()); outState.putString("textStrValue", textStrValue.getText().toString()); } private void restoreMe(Bundle state) { if (state!=null) { textStatus.setText(state.getString("textStatus")); textIntValue.setText(state.getString("textIntValue")); textStrValue.setText(state.getString("textStrValue")); } } private void CheckIfServiceIsRunning() { //If the service is running when the activity starts, we want to automatically bind to it. if (MyService.isRunning()) { doBindService(); } } private OnClickListener btnStartListener = new OnClickListener() { public void onClick(View v){ startService(new Intent(MainActivity.this, MyService.class)); } }; private OnClickListener btnStopListener = new OnClickListener() { public void onClick(View v){ doUnbindService(); stopService(new Intent(MainActivity.this, MyService.class)); } }; private OnClickListener btnBindListener = new OnClickListener() { public void onClick(View v){ doBindService(); } }; private OnClickListener btnUnbindListener = new OnClickListener() { public void onClick(View v){ doUnbindService(); } }; private OnClickListener btnUpby1Listener = new OnClickListener() { public void onClick(View v){ sendMessageToService(1); } }; private OnClickListener btnUpby10Listener = new OnClickListener() { public void onClick(View v){ sendMessageToService(10); } }; private void sendMessageToService(int intvaluetosend) { if (mIsBound) { if (mService != null) { try { Message msg = Message.obtain(null, MyService.MSG_SET_INT_VALUE, intvaluetosend, 0); msg.replyTo = mMessenger; mService.send(msg); } catch (RemoteException e) { } } } } void doBindService() { bindService(new Intent(this, MyService.class), mConnection, Context.BIND_AUTO_CREATE); mIsBound = true; textStatus.setText("Binding."); } void doUnbindService() { if (mIsBound) { // If we have received the service, and hence registered with it, then now is the time to unregister. if (mService != null) { try { Message msg = Message.obtain(null, MyService.MSG_UNREGISTER_CLIENT); msg.replyTo = mMessenger; mService.send(msg); } catch (RemoteException e) { // There is nothing special we need to do if the service has crashed. } } // Detach our existing connection. unbindService(mConnection); mIsBound = false; textStatus.setText("Unbinding."); } } @Override protected void onDestroy() { super.onDestroy(); try { doUnbindService(); } catch (Throwable t) { Log.e("MainActivity", "Failed to unbind from the service", t); } } } src\com.exampleservice\MyService.java: package com.exampleservice; import java.util.ArrayList; import java.util.Timer; import java.util.TimerTask; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.os.Messenger; import android.os.RemoteException; import android.util.Log; public class MyService extends Service { private NotificationManager nm; private Timer timer = new Timer(); private int counter = 0, incrementby = 1; private static boolean isRunning = false; ArrayList<Messenger> mClients = new ArrayList<Messenger>(); // Keeps track of all current registered clients. int mValue = 0; // Holds last value set by a client. static final int MSG_REGISTER_CLIENT = 1; static final int MSG_UNREGISTER_CLIENT = 2; static final int MSG_SET_INT_VALUE = 3; static final int MSG_SET_STRING_VALUE = 4; final Messenger mMessenger = new Messenger(new IncomingHandler()); // Target we publish for clients to send messages to IncomingHandler. @Override public IBinder onBind(Intent intent) { return mMessenger.getBinder(); } class IncomingHandler extends Handler { // Handler of incoming messages from clients. @Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_REGISTER_CLIENT: mClients.add(msg.replyTo); break; case MSG_UNREGISTER_CLIENT: mClients.remove(msg.replyTo); break; case MSG_SET_INT_VALUE: incrementby = msg.arg1; break; default: super.handleMessage(msg); } } } private void sendMessageToUI(int intvaluetosend) { for (int i=mClients.size()-1; i>=0; i--) { try { // Send data as an Integer mClients.get(i).send(Message.obtain(null, MSG_SET_INT_VALUE, intvaluetosend, 0)); //Send data as a String Bundle b = new Bundle(); b.putString("str1", "ab" + intvaluetosend + "cd"); Message msg = Message.obtain(null, MSG_SET_STRING_VALUE); msg.setData(b); mClients.get(i).send(msg); } catch (RemoteException e) { // The client is dead. Remove it from the list; we are going through the list from back to front so this is safe to do inside the loop. mClients.remove(i); } } } @Override public void onCreate() { super.onCreate(); Log.i("MyService", "Service Started."); showNotification(); timer.scheduleAtFixedRate(new TimerTask(){ public void run() {onTimerTick();}}, 0, 100L); isRunning = true; } private void showNotification() { nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); // In this sample, we'll use the same text for the ticker and the expanded notification CharSequence text = getText(R.string.service_started); // Set the icon, scrolling text and timestamp Notification notification = new Notification(R.drawable.icon, text, System.currentTimeMillis()); // The PendingIntent to launch our activity if the user selects this notification PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); // Set the info for the views that show in the notification panel. notification.setLatestEventInfo(this, getText(R.string.service_label), text, contentIntent); // Send the notification. // We use a layout id because it is a unique number. We use it later to cancel. nm.notify(R.string.service_started, notification); } @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i("MyService", "Received start id " + startId + ": " + intent); return START_STICKY; // run until explicitly stopped. } public static boolean isRunning() { return isRunning; } private void onTimerTick() { Log.i("TimerTick", "Timer doing work." + counter); try { counter += incrementby; sendMessageToUI(counter); } catch (Throwable t) { //you should always ultimately catch all exceptions in timer tasks. Log.e("TimerTick", "Timer Tick Failed.", t); } } @Override public void onDestroy() { super.onDestroy(); if (timer != null) {timer.cancel();} counter=0; nm.cancel(R.string.service_started); // Cancel the persistent notification. Log.i("MyService", "Service Stopped."); isRunning = false; } }

    Read the article

  • Passing Activity to non-activity object properly

    - by rayman
    In my app ive got a non-activity object which it's role is being a manager class. many times i need to pass "source activity" to methods as parameter to that manager class in order to make some operations on that activity. for exaple let's assume we have MyActivity which gotta do some toast. so i have this manager class called MyManager, and i have this method in it raiseToast(Activity sourceActivity) { Toast.makeText(sourceActivity, demo, Toast.LENGTH_LONG).show(); } and from Myactivity class we calling that method this way: MyManager manager=new MyManager(); manager.raitetoast(MyActivity.this); it works fine. what I'm asking here, is this a proper way to pass an Activity as parameter to a non-activity object? I'm having a memory leaks on real device(not the emulator), I wonder if this could also causing any reason for that? Thanks Idan.

    Read the article

  • android listview button control

    - by Josemalive
    Hi, I have an android listview filled with items. Every item has a button. This is the template of the my listview. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:paddingBottom="6dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingLeft="5px" android:paddingTop="5px" android:paddingRight="5px" android:gravity="left"> <TextView android:id="@+id/TextView_test1" android:layout_width="200dip" android:paddingLeft="0px" android:layout_height="wrap_content"/> <TextView android:id="@+id/TextView_test2" android:layout_width="250dip" android:paddingLeft="0px" android:layout_height="wrap_content" android:layout_weight="1"/> <TextView android:id="@+id/TextView_test3" android:layout_width="400dip" android:paddingLeft="0px" android:layout_height="wrap_content" android:layout_weight="1"/> <Button android:id="@+id/Button_buttontest" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/Button_buttontest"/> </LinearLayout> How could i handle the click of each button in the activity code? Each button has the same id "Button_buttontest"? Thanks in advance. Best Regards. Jose

    Read the article

  • android: tablerow mixed with columns and multiline text

    - by Yang
    I am trying to have a tablelayout contains several tablerows. One of the rows contains 4 buttons, while the second row contains a very long text. However, the width of the button stretches with the text in the second row. Is there anyway to prevent this? http://img684.imageshack.us/i/tableview1.jpg/ http://img521.imageshack.us/i/tableview2.jpg/ Here is my xml file: (somehow this website is not friendly to xml file) AbsoluteLayout android:id="@+id/widget0" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" TableLayout android:id="@+id/widget28" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_x="0px" android:layout_y="10px" TableRow android:id="@+id/widget29" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" Button android:id="@+id/widget30" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" Button android:id="@+id/widget31" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" Button android:id="@+id/widget32" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" Button android:id="@+id/widget33" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" TableRow android:id="@+id/widget35" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" TextView android:id="@+id/widget40" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextViewTextViewTextViewTextViewTextViewTextView"

    Read the article

  • Updating Activity UI from Different Activity Method?

    - by stormin986
    I have a tab widget where one of the tabs is a chat-type feature. I want to update the chat data at an interval (variable depending on whether the chat tab is active or not). The best approach seemed to be using an AsyncTask in my main TabActivity class, as that would avoid any issues of the chat activity being destroyed while in the background, while an AsyncTask was running. I wanted to ensure that the Activity isn't destroyed and recreated, thus causing my AsyncTask to be unable to modify the actual active Activity's data. However, now that my AsyncTask is in the TabActivity activity, I don't have a direct way to call my Chat's ListAdapter notifyDataSetChanged() from my onPostExecute() method anymore. Is there a way to get a reference to a given Tab's current Activity from the TabHost/TabActivity? Or, alternatively, can I assume my chat activity will never be destroyed as a child activity of the TabActivity activity (well, never destroyed while the TabActivity is active at least), and then just put the AsyncTask in the Chat Activity?

    Read the article

  • Mono for Android Book has been Released!!!!!

    - by Wallym
    If I understand things correctly, and I make no guarantees that I do, our Mono for Android book has been RELEASED!  I'm not quite sure what this means, but my guess is that that it has been printed and is being shipped to various book sellers.So, if you have pre-ordered a copy, its now up to Amazon to send it to you.  Its fully out of my control, Wrox, Wiley, as well as everyone but Amazon.If you haven't bought a copy already, why?  Seriously, go order 8-10 copies for the ones you love.  They'll make great romantic gifts for the ones you love.  Just think at the look on the other person's face when you give them a copy of our book. Here's a little about the book:The wait is over! For the millions of .NET/C# developers who have been eagerly awaiting the book that will guide them through the white-hot field of Android application programming, this is the book. As the first guide to focus on Mono for Android, this must-have resource dives into writing applications against Mono with C# and compiling executables that run on the Android family of devices.Putting the proven Wrox Professional format into practice, the authors provide you with the knowledge you need to become a successful Android application developer without having to learn another programming language. You'll explore screen controls, UI development, tables and layouts, and MonoDevelop as you become adept at developing Android applications with Mono for Android.Develop Android apps using tools you already know—C# and .NETAimed at providing readers with a thorough, reliable resource that guides them through the field of Android application programming, this must-have book shows how to write applications using Mono with C# that run on the Android family of devices. A team of authors provides you with the knowledge you need to become a successful Android application developer without having to learn another programming language. You'll explore screen controls, UI development, tables and layouts, and MonoDevelop as you become adept at planning, building, and developing Android applications with Mono for Android.Professional Android Programming with Mono for Android and .NET/C#:Shows you how to use your existing C# and .NET skills to build Android appsDetails optimal ways to work with data and bind data to controlsExplains how to program with Android device hardwareDives into working with the file system and application preferencesDiscusses how to share code between Mono for Android, MonoTouch, and Windows® Phone 7Reveals tips for globalizing your apps with internationalization and localization supportCovers development of tablet apps with Android 4Wrox Professional guides are planned and written by working programmers to meet the real-world needs of programmers, developers, and IT professionals. Focused and relevant, they address the issues technology professionals face every day. They provide examples, practical solutions, and expert education in new technologies, all designed to help programmers do a better job.Now, go buy a bunch of copies!!!!!If you are interested in iPhone and Android and would like to get a little more knowledgeable in the area of development, you can purchase the 3 pack of books from Wrox on Mobile Development with Mono.  This will cover MonoTouch, Mono for Android, and cross platform methods for using both tools.  A great package in and of itself.  The name of that package is: Wrox Cross Platform Android and iOS Mobile Development Three-Pack 

    Read the article

  • Ghost activity in android

    - by Ari
    My application works as follow: On start I have some AppStartActivity which does something, finishes itself and starts MainActivity if user is logged in or LoginActivity otherwise. LoginActivity finishes itself and starts MainActivity when user log in successfully. On MainActivity I have SomeActivity from which user can logout. Activity stack for this situation is MainActivity > SomeActivity. It is correct, back button works well. When user click LogOut button there is a problem. I need to show LoginActivity but I don't want to have MainActivity and SomeActivity on activity stack anymore. I could resolve this problem if I wouldn't finish AppStartActivity. I could go back then with flag FLAG_ACTIVITY_CLEAR_TOP and it would work well. But here is a problem with back button. I don't want user to come back to this activity with back button. I want it to exit app instead. UPDATED: Flags FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_CLEAR_TASK would be best, but I need it working in API level 9.

    Read the article

  • Android layout with 2 evenly spaced Buttons

    - by Rpond
    I have this layout that works correctly, a relative layout with a text view and two buttons spaced evenly below it. <RelativeLayout android:id="@+id/entrypopup" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="5px" android:visibility="gone" android:layout_below="@+id/ad" android:background="#80000000"> <TextView android:id="@+id/title" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Entry Popup..." android:textColor="#ffffffff" android:textSize="20sp" /> <TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/title"> <TableRow android:layout_weight="1"> <Button android:id="@+id/buttonVisit" android:text="View" android:layout_height="fill_parent" android:layout_width="0dip" android:layout_weight="1"/> <Button android:id="@+id/buttonCancel" android:text="Cancel" android:layout_width="0dip" android:layout_weight="1" android:layout_height="fill_parent"/> </TableRow> </TableLayout> </RelativeLayout> But running layoutopt it says that "this TableRow layout or its TableLayout parent is possible useless". Is there a way to do this layout then without the tables?

    Read the article

  • Drawing lines between views in a TableLayout

    - by RiThBo
    Firstly - sorry if you saw my other question which I deleted. My question was flawed. Here is a better version If I have two views, how do I draw a (straight) line between them when one of them is touched? The line needs to be dynamic so it can follow the finger until it reaches the second view where it "locks on". So, when view1 is touched a straight line is drawn which then follows the finger until it reaches view2. I created a LineView class that extends view, but I don't how to proceed. I read some tutorials but none show how to do this. I think I need to get the coordinates of both view, and then create a path which "updates" on MotionEvent. I can get the coordinates and the ids of the views I want to draw a line between, but the line that I try to draw between them either goes above it, or the line does not reach past the width and height of the view. Any advice/code/clarity would be much appreciated! Here is some code: My layout. I want to draw a line between two views contained in theTableLayout.# <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/activity_game_relative_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TableLayout android:layout_marginTop="35dp" android:layout_marginBottom="35dp" android:id="@+id/tableLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" > <TableRow android:id="@+id/table_row_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dip" > <com.example.view.DotView android:id="@+id/game_dot_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="10dp" /> <com.example.view.DotView android:id="@+id/game_dot_2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="10dp" /> <com.example.view.DotView android:id="@+id/game_dot_3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="10dp" /> </TableRow> <TableRow android:id="@+id/table_row_2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dip" > <com.example.view.DotView android:id="@+id/game_dot_7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="10dp" /> <com.example.view.DotView android:id="@+id/game_dot_8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="10dp" /> <com.example.dotte.DotView android:id="@+id/game_dot_9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="10dp" /> </TableRow> </TableLayout> </RelativeLayout> This is my LineView class. I use this to try and draw the actual line between the points. public class LineView extends View { Paint paint = new Paint(); float startingX, startingY, endingX, endingY; public LineView(Context context) { super(context); // TODO Auto-generated constructor stub paint.setColor(Color.BLACK); paint.setStrokeWidth(10); } public void setPoints(float startX, float startY, float endX, float endY) { startingX = startX; startingY = startY; endingX = endX; endingY = endY; invalidate(); } @Override public void onDraw(Canvas canvas) { canvas.drawLine(startingX, startingY, endingX, endingY, paint); } } And this is my Activity. public class Game extends Activity { DotView dv1, dv2, dv3, dv4, dv5, dv6, dv7; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_game); getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LOW_PROFILE); findDotIds(); RelativeLayout rl = (RelativeLayout) findViewById(R.id.activity_game_relative_layout); LineView lv = new LineView(this); lv.setPoints(dv1.getLeft(), dv1.getTop(), dv7.getLeft(), dv7.getTop()); rl.addView(lv); // TODO: Get the coordinates of all the dots in the TableLayout. Use view tree observer. } private void findDotIds() { // TODO Auto-generated method stub dv1 = (DotView) findViewById(R.id.game_dot_1); dv2 = (DotView) findViewById(R.id.game_dot_2); dv3 = (DotView) findViewById(R.id.game_dot_3); dv4 = (DotView) findViewById(R.id.game_dot_4); dv5 = (DotView) findViewById(R.id.game_dot_5); dv6 = (DotView) findViewById(R.id.game_dot_6); dv7 = (DotView) findViewById(R.id.game_dot_7); } } The views I want to draw lines between are in the TableLayout.

    Read the article

  • using Unity Android In a sub view and add actionbar and style

    - by aeroxr1
    I exported a simple animation from Unity3D (version 4.5) in android project. With eclipse I modified the manifest and added another activity. In this activity I put a button that it makes start the animation,and this is the result. The action bar appear in the main activity but it doesn't in the unity's activity :( How can I add the action bar and the style of the first activity to unity's animation activity ? This is the unity's activity's code : package com.rabidgremlin.tut.redcube; import android.app.NativeActivity; import android.content.res.Configuration; import android.graphics.PixelFormat; import android.os.Bundle; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import com.unity3d.player.UnityPlayer; public class UnityPlayerNativeActivity extends NativeActivity { protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code // Setup activity layout @Override protected void onCreate (Bundle savedInstanceState) { //requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); getWindow().takeSurface(null); //setTheme(android.R.style.Theme_NoTitleBar_Fullscreen); getWindow().setFormat(PixelFormat.RGB_565); mUnityPlayer = new UnityPlayer(this); /*if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true)) getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); */ setContentView(mUnityPlayer); mUnityPlayer.requestFocus(); } // Quit Unity @Override protected void onDestroy () { mUnityPlayer.quit(); super.onDestroy(); } // Pause Unity @Override protected void onPause() { super.onPause(); mUnityPlayer.pause(); } // eliminiamo questa onResume() e proviamo a modificare la onResume() // Resume Unity @Override protected void onResume() { super.onResume(); mUnityPlayer.resume(); } // inseriamo qualche modifica qui // This ensures the layout will be correct. @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mUnityPlayer.configurationChanged(newConfig); } // Notify Unity of the focus change. @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); mUnityPlayer.windowFocusChanged(hasFocus); } // For some reason the multiple keyevent type is not supported by the ndk. // Force event injection by overriding dispatchKeyEvent(). @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_MULTIPLE) return mUnityPlayer.injectEvent(event); return super.dispatchKeyEvent(event); } // Pass any events not handled by (unfocused) views straight to UnityPlayer @Override public boolean onKeyUp(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); } @Override public boolean onTouchEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); } /*API12*/ public boolean onGenericMotionEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); } } And this is the AndroidManifest.xml android:versionCode="1" android:versionName="1.0" > <!-- android:theme="@android:style/Theme.NoTitleBar"--> <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:xlargeScreens="true" /> <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:theme="@android:style/Theme.Holo.Light" > <activity android:name="com.rabidgremlin.tut.redcube.UnityPlayerNativeActivity" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale" android:label="@string/app_name" android:screenOrientation="portrait" > <!--android:launchMode="singleTask"--> <meta-data android:name="unityplayer.UnityActivity" android:value="true" /> <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" /> </activity> <activity android:name="com.rabidgremlin.tut.redcube.MainActivity" android:label="@string/title_activity_main" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="17" android:targetSdkVersion="19" /> <uses-feature android:glEsVersion="0x00020000" /> </manifest>

    Read the article

  • android include tag - invalid layout refernce

    - by Dalibor Frivaldsky
    Hello, I'm having a problem including a different layout through the include tag in the android layout xml file. When specifing the layout reference ( @layout/... ), i'm getting a InflateException in the Eclipse ADT with the following error: InflateException: You must specifiy a valid layout reference. The layout ID @layout/func_edit_simple_calculator_toolbox is not valid. the reference should be valid, as I've selected it from the the list of my other layouts and didnt type it in. I'm using android sdk v2.1 these are the layout files func_edit_simple_calculator_toolbox.xml <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="wrap_content"> <TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content"android:layout_height="wrap_content"> <Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1"></Button> <Button android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2"></Button> <Button android:id="@+id/Button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="3"></Button> <Button android:id="@+id/Button04" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="+"></Button> </TableRow> <TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:id="@+id/Button05" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="4"></Button> <Button android:id="@+id/Button06" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="5"></Button> <Button android:id="@+id/Button07" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="6"></Button> <Button android:id="@+id/Button08" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="-"></Button> </TableRow> </TableLayout> function_editor_layout.xml <?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" > <com.calculoid.FunctionView android:id="@+id/function_view" android:layout_width="fill_parent" android:layout_height="fill_parent"/> <include android:id="@+id/include01" android:layout_width="wrap_content" android:layout_height="wrap_content" layout="@layout/func_edit_simple_calculator_toolbox"></include> </LinearLayout> Does any one know what could be the problem? thanks in advance

    Read the article

  • Android 1.5 - 2.1 Search Activity affects Parent Lifecycle

    - by pacoder
    Behavior seems consistent in Android 1.5 to 2.1 Short version is this, it appears that when my (android search facility) search activity is fired from the android QSR due to either a suggestion or search, UNLESS my search activity in turn fires off a VISIBLE activity that is not the parent of the search, the search parents life cycle changes. It will NOT fire onDestroy until I launch a visible activity from it. If I do, onDestroy will fire fine. I need a way to get around this behavior... The long version: We have implemented a SearchSuggestion provider and a Search activity in our application. The one thing about it that is very odd is that if the SearchManager passes control to our custom Search activity, AND that activity does not create a visible Activity the Activity which parented the search does not destroy (onDestroy doesn't run) and it will not until we call a visible Activity from the parent activity. As long as our Search Activity fires off another Activity that gets focus the parent activity will fire onDestroy when I back out of it. The trick is that Activity must have a visual component. I tried to fake it out with a 'pass through' Activity so that my Search Activity could fire off another Intent and bail out but that didn't work either. I have tried setting our SearchActivity to launch singleTop and I also tried setting its noHistory attribute to true, tried setResult(RESULT_OK) in SearchACtivity prior to finish, bunch of other things, nothing is working. This is the chunk of code in our Search Activity onCreate. Couple of notes about it: If Intent is Action_Search (user typed in their own search and didn't pick a suggestion), we display a list of results as our Search Activity is a ListActivity. In this case when the item is picked, the Search Activity closes and our parent Activity does fire onDestroy() when we back out. If Intent is Action_View (user picked a suggestion) when type is "action" we fire off an Intent that creates a new visible Activity. In this case same thing, when we leave that new activity and return to the parent activity, the back key does cause the parent activity to fire onDestroy when leaving. If Intent is Action_View (user picked a suggestion) when type is "pitem" is where the problem lies. It works fine (the method call focuses an item on the parent activity), but when the back button is hit on the parent activity onDestroy is NOT called. IF after this executes I pick an option in the parent activity that fires off another activity and return to the parent then back out it will fire onDestroy() in the parent activity. Note that the "action" intent ends up running the exact same method call as "pitem", it just bring up a new visual Activity first. Also I can take out the method call from "pitem" and just finish() and the behavior is the same, the parent activity doesn't fire onDestroy() when backed out of. if (Intent.ACTION_SEARCH.equals(queryAction)) { this.setContentView(_layoutId); String searchKeywords = queryIntent.getStringExtra(SearchManager.QUERY); init(searchKeywords); } else if(Intent.ACTION_VIEW.equals(queryAction)){ Bundle bundle = queryIntent.getExtras(); String key = queryIntent.getDataString(); String userQuery = bundle.getString(SearchManager.USER_QUERY); String[] keyValues = key.split("-"); if(keyValues.length == 2) { String type = keyValues[0]; String value = keyValues[1]; if(type.equals("action")) { Intent intent = new Intent(this, EventInfoActivity.class); Long longKey = Long.parseLong(value); intent.putExtra("vo_id", longKey); startActivity(intent); finish(); } else if(type.equals("pitem")) { Integer id = Integer.parseInt(value); _application._servicesManager._mapHandlerSelector.selectInfoItem(id); finish(); } } } It just seems like something is being held onto and I can't figure out what it is, in all cases the Search Activity fires onDestroy() when finish() is called so it is definitely going away. If anyone has any suggestions I'd be most appreciative. Thanks, Sean Overby

    Read the article

  • Android Textview Italic and wrap_contents

    - by Faisal khan
    I am using 3 italic textviews with different colors <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:id="@+id/submittedBy" android:paddingTop="10dip"> <ImageView android:id="@+id/subByImg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:layout_gravity="bottom" android:src="@drawable/submitted_by_arrow"/> <TextView android:id="@+id/submitLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="Submitted by" android:textStyle="italic" android:textSize="12sp" android:textColor="@color/gray" android:paddingLeft="5dip"/> <TextView android:id="@+id/submitName" android:textStyle="italic" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="12sp" android:textColor="@color/maroon_dark" android:paddingLeft="10dip"/> <TextView android:id="@+id/submitByDate" android:textStyle="italic" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:textSize="12sp" android:textColor="@color/gray" android:paddingLeft="10dip"/> </LinearLayout> I wonder every last character is not displaying properly specially name displayed in the middle is "Dan Buckland" and it it is missing last character looks like "Dan Bucklano" Also tell me pls how can have textview italic and bold both..

    Read the article

  • Why does Android Account & Sync reboot when trying to find my settings activity?

    - by mobibob
    I have an activity that I can declare as Launcher category and it launches just fine from the home screen. However, when I try to hook-up the same activity into my SyncAdapter's settings activity and open it from the Accounts & Sync page - MySyncAdapter - (touch account listing) it aborts with a system fatal error (reboots phone). Meanwhile, my SyncAdapter is working other respects. Here is the log at point of impact: 01-13 12:31:00.976 5024 5038 I ActivityManager: Starting activity: Intent { act=android.provider.Settings.ACTION_SYNC_SETTINGS flg=0x10000000 cmp=com.myapp.android.syncadapter.ui/SyncAdapterSettingsActivity.class (has extras) } 01-13 12:31:00.985 5024 5038 E AndroidRuntime: *** FATAL EXCEPTION IN SYSTEM PROCESS: android.server.ServerThread 01-13 12:31:00.985 5024 5038 E AndroidRuntime: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.myapp.android.syncadapter.ui/SyncAdapterSettingsActivity.class}; have you declared this activity in your AndroidManifest.xml? 01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404) 01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378) 01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.app.ContextImpl.startActivity(ContextImpl.java:622) 01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.preference.Preference.performClick(Preference.java:828) 01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:190) 01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.widget.AdapterView.performItemClick(AdapterView.java:284) 01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.widget.ListView.performItemClick(ListView.java:3382) 01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696) 01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:587) 01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:92) 01-13 12:31:00.985 5024 5038 E AndroidRuntime: at android.os.Looper.loop(Looper.java:123) 01-13 12:31:00.985 5024 5038 E AndroidRuntime: at com.android.server.ServerThread.run(SystemServer.java:517) 01-13 12:31:00.985 5024 5038 I Process : Sending signal. PID: 5024 SIG: 9 01-13 12:31:01.005 5019 5019 I Zygote : Exit zygote because system server (5024) has terminated 01-13 12:31:01.015 1211 1211 E installd: eof Here is a snippet from my manifest file: <activity android:name="com.myapp.android.syncadapter.ui.SyncAdapterSettingsActivity" android:label="@string/title_settings" android:windowSoftInputMode="stateAlwaysHidden|adjustPan"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.MAIN" /> <action android:name="android.provider.Settings.ACTION_SYNC_SETTINGS"/> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>

    Read the article

  • Passing Activity A's data into Activity B

    - by user1058153
    What i am trying to show here is that I am trying to pass the data in Activity A to Activity B. Activity A mainly there are 3 textbox for me to key in something then a button to go to Activity B(Confirmation Page) and in Activity B, i am able to show what i have keyed in Activity A. I am new to Android, so can someone guide me through this? In Activity A @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activitya); Textview01 = (EditText) this.findViewById(R.id.txtView1); Textview02 = (EditText) this.findViewById(R.id.txtView2); Textview03 = (EditText) this.findViewById(R.id.txtView3); mButton = (Button) findViewById(R.id.button); mButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent i = new Intent(ActivityA.this, ActivityB.class); i.putExtra("Textview01", txtView1.getText().toString()); i.putExtra("Textview02", txtView2.getText().toString()); i.putExtra("Textview03", txtView3.getText().toString()); startActivity(i); In Activity B. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.confirmbooking); TextView txtPickup = (TextView) this.findViewById(R.id.txtPickup); TextView txtLocation = (TextView) this.findViewById(R.id.txtLocation); TextView txtDestination = (TextView) this.findViewById(R.id.txtDestination); txtLocation.setText(getIntent().getStringExtra("Location")); txtPickup.setText(getIntent().getStringExtra("Pick Up Point")); txtDestination.setText(getIntent().getStringExtra("Destination")); In my Activity B XML <?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"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="txtView01:" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/txtView01"></TextView> <TextView android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="txtView02:"></TextView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/txtView02"></TextView> <TextView android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="txtView03:"></TextView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/txtView03"></TextView> <Button android:id="@+id/btnButton" android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="Book now" /> </LinearLayout> Can someone tell me if this is correct? I'm getting some error like a popup Instrumental.class. LogCat shows : 11-26 17:27:40.895: INFO/ActivityManager(52): Starting activity: Intent { cmp=ActivityA/.ActivityB (has extras) } 11-26 17:27:42.956: DEBUG/dalvikvm(252): GC_EXPLICIT freed 156 objects / 11384 bytes in 346ms 11-26 17:27:47.815: DEBUG/dalvikvm(288): GC_EXPLICIT freed 31 objects / 1496 bytes in 161ms

    Read the article

  • Child Activity in Android

    - by Martin Marinov
    So I have two Activities. The main is called Main, and the child one is called Child. When a button is clicked in the main activity it triggers the following piece of code: Intent i = new Intent(Main.this, Child.class); Main.this.startActivity(i); That opens the Child activity. As soon as I call finish() or press the back button within the child activity instead of going back to the main one, the app just closes. Can you give me a hint where the problem might be :( P.S. By trial and error I found out that if edit AndroidManifest.xml and add android:theme="@android:style/Theme.Dialog" within the declaration of Child the back button and calling finish() behaves as expected: closes the child activity and brings the main into focus. The problem is that when I start typing in an EditText the screen starts flickering (rather bizzare). So I can't use it as a dialog. My main activity uses the camera, so that might be making problems. Although when the child activity is started, the onPause event is fired and it stops the camera until onResume is called.

    Read the article

  • Remove Activity as Default Launcher

    - by sixeightzero
    I set my activity as a default launcher to intercept home button clicks like so: <activity android:name=".ExampleActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.HOME" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> When my activity, ExampleActivity is launched, if i click the home key, I get prompted to choose. If I select make this my default and chose my activity, I am stuck In my activity as desired. The problem is, when I leave the activity, I try to remove my activity from the default launcher, but am unsuccessful. I have tried: ComponentName componentName = new ComponentName( "com.example.exampleactivity", "com.example.exampleactivity.class"); pm.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP); And: PackageManager pm = getActivity().getPackageManager(); ComponentName name = new ComponentName(this, "com.example.exampleactivity.class"); pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0); But my designation for the home is never removed. Does anyone have a working way to fix the above? I only wan't the home button to be default for a specific activity, not my entire application. When I leave the activity, it should be removed and restored to default.

    Read the article

  • Android programming. Application stopped unexpectedly.

    - by user277704
    I've just created a prototype of interface for my android app and tried to run it. Unfortunately I get an error that my app has stopped unexpectedly (my reputation doesn't allow me to post images so follow my links): screenshot of error message This is layout mode of editing. Everything looks as I want so there shouldn't be errors: mobileka.freehostia.com/3.png (I can post only one hyperlink...) This is my main.xml code: <code> <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="top" android:background="@drawable/back" > <TextView android:id="@+id/score" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text = "@string/scoreT" android:textColor="@string/scoreColor" android:gravity = "left" android:typeface="serif" android:textStyle="bold|italic" android:textSize="16sp" android:paddingLeft = "10px" android:paddingTop="4px"/ <TextView android:id = "@+id/scoreTxt" android:layout_toRightOf="@+id/score" android:textSize="16sp" android:paddingTop = "5px" android:paddingLeft="4px" android:typeface="serif" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" 0" android:textColor="@string/scoreTextColor" android:gravity = "left"/> <TextView android:id = "@+id/scoreSeparator" android:layout_toRightOf="@+id/scoreTxt" android:textSize="16sp" android:paddingTop = "3px" android:paddingLeft="4px" android:typeface="serif" android:textStyle="bold" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="|" android:textColor="@string/scoreColor" android:gravity = "left"/> <TextView android:id = "@+id/timerTxt" android:layout_alignParentRight="true" android:textSize="16sp" android:paddingRight="10px" android:paddingTop="4px" android:typeface="serif" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@string/scoreTextColor" android:gravity = "right" android:text="00:00" /> <TextView android:id = "@+id/timer" android:layout_toLeftOf="@+id/timerTxt" android:textColor="@string/scoreColor" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="16sp" android:padding = "3px" android:typeface="serif" android:textStyle="bold|italic" android:text="@string/timerT" android:gravity = "left"/> <TextView android:id = "@+id/timerSeparator" android:layout_toLeftOf="@+id/timer" android:textSize="16sp" android:paddingTop = "3px" android:paddingLeft="4px" android:typeface="serif" android:textStyle="bold" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="|" android:textColor="@string/scoreColor" android:gravity = "left"/> <ImageButton android:id="@+id/buttonOne" android:layout_below="@+id/score" android:layout_marginTop="40px" android:layout_marginLeft="14px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="true" android:src="@drawable/inactive"/> <ImageButton android:id="@+id/buttonTwo" android:layout_toRightOf="@+id/buttonOne" android:layout_marginTop="63px" android:layout_marginLeft="10px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/inactive" /> <ImageButton android:id="@+id/buttonThree" android:layout_toRightOf="@+id/buttonTwo" android:layout_marginTop="63px" android:layout_marginLeft="10px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/inactive" /> <ImageButton android:id="@+id/buttonFour" android:layout_toRightOf="@+id/buttonThree" android:layout_marginTop="63px" android:layout_marginLeft="10px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/inactive" /> <ImageButton android:id="@+id/buttonFive" android:layout_below="@+id/buttonOne" android:layout_marginTop="40px" android:layout_marginLeft="14px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/inactive" /> <ImageButton android:id="@+id/buttonSix" android:layout_toRightOf="@+id/buttonFive" android:layout_marginTop="164px" android:layout_marginLeft="10px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/inactive" /> <ImageButton android:id="@+id/buttonSeven" android:layout_toRightOf="@+id/buttonSix" android:layout_marginTop="164px" android:layout_marginLeft="10px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/inactive" /> <ImageButton android:id="@+id/buttonEight" android:layout_toRightOf="@+id/buttonSeven" android:layout_marginTop="164px" android:layout_marginLeft="10px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/inactive" /> <ImageButton android:id="@+id/buttonNine" android:layout_below="@+id/buttonEight" android:layout_marginTop="40px" android:layout_marginLeft="14px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/inactive" /> <ImageButton android:id="@+id/buttonTen" android:layout_toRightOf="@+id/buttonNine" android:layout_marginTop="264px" android:layout_marginLeft="10px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/inactive" /> <ImageButton android:id="@+id/buttonEleven" android:layout_toRightOf="@+id/buttonTen" android:layout_marginTop="264px" android:layout_marginLeft="10px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/inactive" /> <ImageButton android:id="@+id/buttonTwelve" android:layout_toRightOf="@+id/buttonEleven" android:layout_marginTop="264px" android:layout_marginLeft="10px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/inactive" /> And this is my logcat errors (p.s. line #12 is the first TextView in main.xml): 03-26 22:59:31.670: WARN/dalvikvm(185): threadid=3: thread exiting with uncaught exception (group=0x4001b188) 03-26 22:59:31.727: ERROR/AndroidRuntime(185): Uncaught handler: thread main exiting due to uncaught exception 03-26 22:59:31.784: ERROR/AndroidRuntime(185): java.lang.RuntimeException: Unable to start activity ComponentInfo{kz.androidmarket.www.randomtest1/kz.androidmarket.www.randomtest1.randomTest1}: android.view.InflateException: Binary XML file line #12: Error inflating class 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.app.ActivityThread.access$2200(ActivityThread.java:119) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.os.Handler.dispatchMessage(Handler.java:99) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.os.Looper.loop(Looper.java:123) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.app.ActivityThread.main(ActivityThread.java:4363) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at java.lang.reflect.Method.invokeNative(Native Method) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at java.lang.reflect.Method.invoke(Method.java:521) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at dalvik.system.NativeStart.main(Native Method) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.view.LayoutInflater.createView(LayoutInflater.java:513) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.view.LayoutInflater.inflate(LayoutInflater.java:407) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.app.Activity.setContentView(Activity.java:1622) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at kz.androidmarket.www.randomtest1.randomTest1.onCreate(randomTest1.java:11) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): ... 11 more 03-26 22:59:31.784: ERROR/AndroidRuntime(185): Caused by: java.lang.reflect.InvocationTargetException 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.widget.TextView.(TextView.java:320) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at java.lang.reflect.Constructor.constructNative(Native Method) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at java.lang.reflect.Constructor.newInstance(Constructor.java:446) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.view.LayoutInflater.createView(LayoutInflater.java:500) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): ... 22 more 03-26 22:59:31.784: ERROR/AndroidRuntime(185): Caused by: android.content.res.Resources$NotFoundException: File #ffff9900 from drawable resource ID #0x7f040002: .xml extension required 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.content.res.Resources.loadColorStateList(Resources.java:1820) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.content.res.TypedArray.getColorStateList(TypedArray.java:289) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): at android.widget.TextView.(TextView.java:627) 03-26 22:59:31.784: ERROR/AndroidRuntime(185): ... 26 more Could anybody help me?

    Read the article

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