[Q] unable to switch activity - Android Software Development

Hi,
I am new to android development. I am facing problem in switching between activities. I am attaching the code files ... Please help me solve this problem
Being a new user the Forum doesn't allow me to write atTheRateSign in my message ... I am replacing it with % sign. Please don't confuse it.
Main Activity:
Code:
package swz.pkg;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class SWMainActivity extends Activity {
/** Called when the activity is first created. */
%Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnMSrch = (Button) findViewById(R.id.btnClosetSearch);
try{
btnMSrch.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(v.getContext(),ClosetSearchAct.class);
startActivityForResult(myIntent,0);
}
});
}
catch (Exception ex)
{
System.out.println("---------------------******------------------------");
ex.printStackTrace();
System.out.println();
System.out.println("---------------------******------------------------");
}
}
}
main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="%+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="ht ... android"
>
<Button
android:id="%+id/btnMeasurementSearch"
android:layout_width="fill_parent"
android:layout_height="150px"
android:background="#ffffffff"
android:text="Measurement Search"
android:textSize="26sp"
android:typeface="serif"
android:textStyle="bold"
android:textColor="#ff8c2528"
android:layout_x="0px"
android:layout_y="47px"
>
</Button>
<Button
android:id="%+id/btnClosetSearch"
android:layout_width="fill_parent"
android:layout_height="150px"
android:text="Closet Search"
android:textSize="26sp"
android:typeface="serif"
android:textStyle="bold"
android:textColor="#ff462556"
android:layout_x="0px"
android:layout_y="213px"
>
</Button>
</AbsoluteLayout>
closetSearch activity(The next activity I want to move to):
Code:
package swz.pkg;
import android.app.Activity;
import android.os.Bundle;
public class ClosetSearchAct extends Activity {
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.closetsearchact);
}
}
closetsearchact.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="%+id/widget1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="ht .... android"
>
<Spinner
android:id="%+id/spinner1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="0px"
android:layout_y="33px"
>
</Spinner>
<Spinner
android:id="%+id/spinner2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="0px"
android:layout_y="101px"
>
</Spinner>
<Spinner
android:id="%+id/spinner3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="0px"
android:layout_y="173px"
>
</Spinner>
<ImageButton
android:id="%+id/btnReg"
android:layout_width="128px"
android:layout_height="wrap_content"
android:src="%drawable/reg"
android:layout_x="151px"
android:layout_y="279px"
>
</ImageButton>
<ImageButton
android:id="%+id/btnSearch"
android:layout_width="114px"
android:layout_height="49px"
android:src="%drawable/search"
android:layout_x="37px"
android:layout_y="279px"
>
</ImageButton>
</AbsoluteLayout>
AndroidManifest.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="ht ... android"
package="swz.pkg"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="%drawable/icon" android:label="%string/app_name">
<activity android:name=".SWMainActivity"
android:label="%string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ClosetSearchAct" android:label="%string/app_name"> </activity>
</application>
</manifest>

Related

GoogleMap-Android

Hi all,
I am trying to get map in android Emulator, But I have error message when i run the application.How to rectify this error?
My Code:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.googlemapsandroid"
android:versionCode="1"
android:versionName="1.0">
<uses-library android:name="com.google.android.maps.map" />
<application android:icon="@drawable/worldmap" android:label="@string/app_name">
<activity android:name=".GoogelMapsAndroid"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
androidrientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0ubDx0zU6vaeSSZoV0oyPB4zi7y8T2hKSZfAyZw"
/>
</RelativeLayout>
GoogleMapsAndroid.java
package com.android.googlemapsandroid;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class GoogleMapsAndroid extends MapActivity
{
MapView mapview;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapview=(MapView)findViewById(R.id.mapview);
mapview.setSatellite(true);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
I have error message:
java lang Runtime Exception Unable to instantiate ComponentInfo{com.android.googlemapsandroid/com.android.googlemapsandroid.MapsActivity}java.lang.RuntimeException: stub
Do you use Google APIs target in an emulator?
No. How to use Google api.
dineshsubramanian said:
No. How to use Google api.
Click to expand...
Click to collapse
This is what I mean:
http://img40.imageshack.us/f/screenshotcreatenewandr.png/
Thanks for your reply.
I will try in Google Api.
Now i ran in google api. but i have error message
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.googlemapdemo/com.googledemo.GoogleMapDemo}: android.view.InflateException: Binary XML file line #6: Error inflating class com.google.android.maps.MapView.

[Q] ArrayAdapter and custom layout

Hi , i'm studyng android Adapter
I want create a ListView with a serie of data. Ok , the code.
Code:
/*
Activity class
*/
package it.actiondesign.android.app.userdata;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
public class UserDataActivity extends Activity {
ArrayList<UserData> allUsers = new ArrayList<UserData>();
private ListView myListView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myListView= (ListView) findViewById(R.id.datalist);
createFakeData();
int resID = R.layout.user_row;
// data_adpater = new ArrayAdapter<UserData>(this, R.layout.user_row, allUsers);
// myListView.setAdapter(data_adpater);
}
//fill ArrayList with fake data
private void createFakeData() {
UserData first = new UserData("Frank", "Smith", 30, "Chicaco");
UserData second = new UserData("Tania", "Roger", 20, "Los Angeles");
allUsers.add(first);
allUsers.add(second);
}
}
here the main.xml
Code:
<?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"
>
<ListView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/datalist"></ListView>
</LinearLayout>
I create a class of data
Code:
public class UserData {
private String name;
private String surname;
private int age;
private String from;
public UserData(String _name , String _surname, int _age, String _from){
this.name= _name;
this.surname= _surname;
this.age= _age;
this.from= _from;
}
public String getName(){
return name;
}
public String getSurname(){
return surname;
}
public int getAge(){
return age;
}
public String getFrom(){
return from;
}
}
custom layout of a single item
Code:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:text="Name: "
android:id="@+id/TextView01" android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<TextView android:text=""
android:id="@+id/tName" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="@color/red">
</TextView>
</TableRow>
<TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:text="Surname: "
android:id="@+id/TextView02" android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<TextView android:text=""
android:id="@+id/tSurname" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="@color/red">
</TextView>
</TableRow>
<TableRow android:id="@+id/TableRow03" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:text="From: "
android:id="@+id/TextView03" android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<TextView android:text=""
android:id="@+id/tFrom" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="@color/red">
</TextView>
</TableRow>
<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:text="Age: "
android:id="@+id/TextView03" android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<TextView android:text=""
android:id="@+id/tAge" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="@color/red">
</TextView>
</TableRow>
</TableLayout>
In other layout a create a ArrayAdpater<String> and all was simple, but how can fill TextView (tName, tSurname, tAge, tFrom) with data.
Now I use a simple ArrayList after i load data from WebService
Depends what kind of data your are retrieving. In your layout you have 4 textview 'rows'. Maybe instead of this you could use a listview?

[NEWBIE] Intents not working properly..

Hey there. i was experimenting with intents.. While I got stuck in this bug. I am almost positive, that my java classes have been coded correctly...
I think, its the android manifest.. The intent filters have not been setup correctly... However I will be posting.. all of my code and the logcat here...
Please help me.. Thanks in advance!
Manifest.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.intents"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.intents.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>
<activity
android:name="com.example.intents.SecondActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
activity_xml.xml
Code:
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:layout_width = "fill_parent"
android:layout_height="wrap_content"
android:text="Click for second Activity"
android:onClick="onClick"
android:id="@+id/button1"
/>
</RelativeLayout>
second_act.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tvSecond"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Enter your name! " />
<Button
android:id="@+id/logOn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hit to Login"
android:onClick = "onClick" />
</LinearLayout>
MainActivity.java
Code:
package com.example.intents;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
int request_Code = 1;
/** Called when the activity is first created. */
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View v) {
Intent i = new Intent("com.example.intents.MainActivity");
i.putExtra("str1", "This is str1");
i.putExtra("age1", 16);
Bundle ex = new Bundle();
ex.putString("str2", "this is str2 and a bundle String");
ex.putInt("age2", 22);
i.putExtras(ex);
startActivityForResult(i, 1);
}
protected void onActivityResult(int requestCode, int ResultCode, Intent data) {
if (requestCode == 1) {
if (ResultCode == RESULT_OK) {
Toast.makeText(this,
Integer.toString(data.getIntExtra("age3", 0)),
Toast.LENGTH_SHORT).show();
Toast.makeText(this, data.getData().toString(),
Toast.LENGTH_LONG).show();
}
}
}
}
SecondActivity.xml
Code:
package com.example.intents;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class SecondActivity extends Activity {
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.second_act);
Toast.makeText(this, getIntent().getStringExtra("str1"),
Toast.LENGTH_SHORT).show();
Toast.makeText(this, getIntent().getIntExtra("age1", 0),
Toast.LENGTH_SHORT).show();
Bundle bundle = getIntent().getExtras();
Toast.makeText(this, bundle.getString("str2"), Toast.LENGTH_SHORT)
.show();
Toast.makeText(this, Integer.toString(bundle.getInt("age2")),
Toast.LENGTH_SHORT).show();
}
public void onClick(View v) {
Intent i = new Intent();
i.putExtra("age3", 45);
i.setData(Uri.parse("Something has been passed to main aactivity"));
setResult(RESULT_OK, i);
finish();
}
}
Logcat[only the portion highlighted in red! ]
Uploaded here, for a better view..
hiphop12ism said:
Hey there. i was experimenting with intents.. While I got stuck in this bug. I am almost positive, that my java classes have been coded correctly...
I think, its the android manifest.. The intent filters have not been setup correctly... However I will be posting.. all of my code and the logcat here...
Please help me.. Thanks in advance!
Click to expand...
Click to collapse
OK, so first of all, in your manifest, you do not need to create an intent-filter, that is just if an activity needs to be launched from another application.
Then, when you create your Intent to start the SecondActivity, do it like this:
Code:
Intent i = new Intent(this, SecondActivity.class);
// put extras and startforResult here
The Error in the logcat states that it could not find the activity, so I suppose this is why
Code:
<activity
android:name="com.example.intents.SecondActivity"
android:label="@string/app_name" >
<intent-filter>
[B]<action android:name="[COLOR="Red"]android.intent.action.SecondActivity[/COLOR]" />[/B]
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
The bold should be referencing the same intent you are trying to call. Change the red text portion above to "com.example.intents.SecondActivity" and use the same to call the intent.
example: Intent i = new Intent("com.example.intents.SecondActivity");
The red text should match each other.
Still crashing!
zalez said:
Code:
<activity
android:name="com.example.intents.SecondActivity"
android:label="@string/app_name" >
<intent-filter>
[B]<action android:name="[COLOR="Red"]android.intent.action.SecondActivity[/COLOR]" />[/B]
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
The bold should be referencing the same intent you are trying to call. Change the red text portion above to "com.example.intents.SecondActivity" and use the same to call the intent.
example: Intent i = new Intent("com.example.intents.SecondActivity");
The red text should match each other.
Click to expand...
Click to collapse
I changed the code, as you said.. But it is still not working...
I am uploading the manifest, and the MainActivity.java again..
Mainfest:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.intents"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.intents.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>
<activity
android:name="com.example.intents.SecondActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.intents.SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
Code:
package com.example.intents;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View v) {
Intent i = new Intent("com.example.intents.SecondActivity");
i.putExtra("str1", "This is str1");
i.putExtra("age1", 16);
Bundle ex = new Bundle();
ex.putString("str2", "this is str2 and a bundle String");
ex.putInt("age2", 22);
i.putExtras(ex);
startActivityForResult(i, 1);
}
protected void onActivityResult(int requestCode, int ResultCode, Intent data) {
if (requestCode == 1) {
if (ResultCode == RESULT_OK) {
Toast.makeText(this,
Integer.toString(data.getIntExtra("age3", 0)),
Toast.LENGTH_SHORT).show();
Toast.makeText(this, data.getData().toString(),
Toast.LENGTH_LONG).show();
}
}
}
}
It is giving errors because of how you are trying to get the strings from the intent in SecondActivity.
replace what you have in your SecondActivity onCreate with the below.
Code:
Intent intent = getIntent();
Toast.makeText(this, intent.getStringExtra("str1"), Toast.LENGTH_LONG).show();
Toast.makeText(this, String.valueOf(intent.getIntExtra("age1", 0)), Toast.LENGTH_LONG).show();
Bundle bundle = intent.getExtras();
Toast.makeText(this, bundle.getString("str2"), Toast.LENGTH_SHORT)
.show();
Toast.makeText(this, Integer.toString(bundle.getInt("age2")),
Toast.LENGTH_SHORT).show();
Thank you, finally it worked :thumbup:
Sent from my GT-S6102 using xda app-developers app

Widget not working

Hey, fellas.. I was learning about widgets. But I got stuck at the very beginning. I was trying to make the simplest of a widget. Firstly, I made an app, that only has one textview on it. When clicked , it shows the number of times it has been clicked. Then I tried to make a widget of the same.
But when I click over the widget, nothing happens. It just shows the initialized number '0'. The debugging goes fine. There is no ANR errors.
But I am not able to figure out the logical error. As the debugging goes alright, I don't think, the logcat will be necessary.
However, If required , I will provide it too. For now, I am uploading the AppWidget.class, widget.xml, manifest.xml, widget_provider.xml :::
THE APPWIDGET.CLASS:
Code:
package com.example.increment;
import android.app.IntentService;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;
public class AppWidget extends AppWidgetProvider {
int c = 0;
[user=439709]@override[/user]
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction() == null)
context.startService(new Intent(context, ToggleService.class));
else
super.onReceive(context, intent);
}
[user=439709]@override[/user]
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// TODO Auto-generated method stub
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
private class ToggleService extends IntentService {
public ToggleService() {
super("AppWidget$ToggleService");
// TODO Auto-generated constructor stub
}
[user=439709]@override[/user]
protected void onHandleIntent(Intent intent) {
// TODO Auto-generated method stub
ComponentName me = new ComponentName(this, AppWidget.class);
AppWidgetManager mgr = AppWidgetManager.getInstance(this);
mgr.updateAppWidget(me, buildUpdate(this));
}
private RemoteViews buildUpdate(Context context) {
// TODO Auto-generated method stub
RemoteViews rm = new RemoteViews(context.getPackageName(),
R.layout.widget);
c++;
String s = String.valueOf(c);
rm.setTextViewText(R.id.t2, s);
Intent i = new Intent(this, AppWidget.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
rm.setOnClickPendingIntent(R.id.t2, pi);
return rm;
}
}
}
THE WIDGET.XML
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/t2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:clickable="true" />
</LinearLayout>
THE WIDGET_PROVIDER.XML:
Code:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minHeight="100sp"
android:minWidth="100sp"
android:updatePeriodMillis="1000"
android:initialLayout="@layout/widget">
</appwidget-provider>
THE MANIFEST.XML:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.increment"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.increment.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>
<receiver
android:name="com.example.increment.AppWidget"
android:icon="@drawable/ic_launcher"
android:label="tanmay" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_provider" />
</receiver>
<service android:name=".AppWidget$ToggleService" >
</service>
</application>
</manifest>
Thanks in advance..

2.3.3 to 4.2.2 Http Get - Help me conquer learning curve

Hey all!
New to Android but not developing. App runs great with emulator running Android 2.3.3. When I install the app to my phone (Samsung Galaxy 4S Active) runnnig Android 4.2.2, the Http Get execute command on the client does not seem to happen. I get no data back reported to my TextView.
I know there is some learning curve I'm missing here, and would appreciate some guidance.
HttpExample.java
Code:
package com.example.test;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HttpExample extends Activity {
TextView httpStuff;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.httpex);
httpStuff = (TextView) findViewById(R.id.tvHttp);
GetMethodEx test = new GetMethodEx();
try {
String returned = test.getInternetData();
httpStuff.setText(returned);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
GetMethodEx.java
Code:
package com.example.test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
public class GetMethodEx {
public String getInternetData () throws Exception {
BufferedReader in = null;
String data = null;
try {
HttpClient client = new DefaultHttpClient();
URI website = new URI("CANTPOSTURL");
HttpGet request = new HttpGet();
request.setURI(website);
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String l = "";
String nl = System.getProperty("line.separator");
while ((l = in.readLine()) !=null) {
sb.append(l + nl);
}
in.close();
data = sb.toString();
return data;
}finally {
if (in !=null) {
try {
in.close();
return data;
}catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
AndroidManifest.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="CANTPOSTURL"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.test.HttpExample"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
httpex.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="CANTPOSTURL"
xmlns:tools="CANTPOSTURL"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".HttpActivity">
<ScrollView android:layout_height="fill_parent" android:layout_width="fill_parent">
<TextView
android:id="@+id/tvHttp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading Data" >
</TextView>
</ScrollView>
</LinearLayout>
I would post the logcat but there really is no issue at 2.3.3... just need to know what i'm missing going to 4.2.2.
Thanks in advance, I know this should be easy for you all.

Categories

Resources