Hello,
I wanted to know what is the difference between Context.startService(intent) and startService(intent) and does it matter which one is used?
Thank you
pbutton.setOnClickListener(new OnClickListener()
{ private AlertDialog show;
public void onClick(View arg0)
{
if ((input1.getText().length() == 0) || (input1.getText().toString().equals(" ")) || (input2.getText().length() == 0) || (input2.getText().toString().equals(" "))|| (input1.getText().toString().equals(""))||(input2.getText().toString().equals("")))
{
show = new AlertDialog.Builder(MainActivity.this).setTitle("Error").setMessage("Some inputs are empty").setPositiveButton("OK", null).show();
}
double result = new Double(input1.getText().toString())+ new Double(input2.getText().toString());
output.setText(Double.toString(result));
}
I've also tried passing the context which also doesn't work
Hi
Were now testing our application with a few friends. Sometimes there are some errors which dont throw an exception. So I don't really know whats the problem was. So i thought it would be a good idea to implement a menu item which allows to send the logcat file to a email adress, so that we can examine the logcat.
Unfortunately I didnt found a hint in the Internet how to extract the Logcat from a phone. How to send a email shouldn't be the problem.
I would like to have a checkbox preference that takes the user to a new (sub)preference screen if the user presses on the actual text (and not on the checkbox to the right).
Just as the control under Settings - Wireless - Mobile Network Settings - Access Point Names.
I have used the following code in setting alarm time in AlarmManager class. Now Suppose my device current date 9-july-2012 11:31:00, Now suppose i set set a alarm at 9-july-2012 11:45:00, then it works fine and pop-up an alarm at that time. But if i set an alarm at 10-aug-2012 11:40:00, then as soon as exit the app the alarm pop-up, which is wrong because i set an alarm at month of august, So why this happen, is anything wrong in my code. if anyone knows help me to solve this out.
Code For Setting Alarm time in AlarmManager class
Intent myIntent = new Intent(context, AlarmService.class);
PendingIntent pendingIntent = PendingIntent.getService(context, i, myIntent, i);
AlarmManager alarmManager = (AlarmManager)context.getSystemService(AlarmService.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.MILLISECOND, (int) dateDifferenceFromSystemTime(NoteManager.getSingletonObject().getAlarmTime(i)));
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
public static long dateDifferenceFromSystemTime(Date date)
{
long difference = 0;
try
{
Calendar c = Calendar.getInstance();
difference = date.getTime() - c.getTimeInMillis();
if (difference < 0)
{
// if difference is -1 - means alarm time is of previous time then current
// then firstly change it to +positive and subtract form 86400000 to get exact new time to play alarm
// 86400000-Total no of milliseconds of 24hr Day
difference = difference * -1;
difference = 86400000 - difference;
}
}
catch (Exception e)
{
e.printStackTrace();
}
return difference;
}
Service class which pop-up alarm when matches time
public class AlarmService extends IntentService
{
public void onCreate()
{
super.onCreate();
}
public AlarmService()
{
super("MyAlarmService");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
super.onStartCommand(intent, startId, startId);
return START_STICKY;
}
@Override
protected void onHandleIntent(Intent intent)
{
startActivity(new Intent(this,AlarmDialogActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
}
I want to parse my json by fromJson class but I am unable to understand what should be the structure of my class if my json is like below:
String json = "{"Result":{"Status":"SUCCESS","Message":""},"Response":{"Token":"ca0d7507-3907-4eed-af19-ad256bc71088","ZoneUrl":"https:\/\/qa.tritononline.com\/","CustomerID":1,"UserID":29,"DefaultLanguageID":1,"ZoneID":1,"IsTritonIntegrated":false,"Language":[{"LanguageId":1,"Language":"English","IsSelected":false}]}}"
This is what I want to do
Response res = new Response();
Gson gson = new Gson();
res = gson.fromJson(json, Response.class);
I want to know what all variable should I take in Response class.
I'm trying to set up this enum so that it has the ability to return the correct image, though I'm struggling with a way to incorporate the context since it is in a separate class.
public enum CubeType
{
GREEN {
public Drawable getImage()
{
return Context.getResources().getDrawable( R.drawable.cube_green );
}
};
abstract public Drawable getImage();
}
The error I'm getting is:
Cannot make a static reference to the non-static method getResources() from the type Context
I'm trying to find a way to properly handle setting up an activity where its orientation is determined from data in the intent that launched it. This is for a game where the user can choose levels, some of which are int portrait orientation and some are landscape orientation. The problem I'm facing is that setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) doesn't take effect until the activity is fully loaded. This is a problem for me because I do some loading and image processing during startup, which I'd like to only have to do once.
Currently, if the user chose a landscape level:
the activity starts onCreate(), defaulting to portrait
discovers from analysing its launching Intent that it should be in landscape orientation
continues regardless all the way to onResume(), loading information and performing other setup tasks
at this point setRequestedOrientation kicks in so the application runs through onPause() to onDestroy()
it then again starts up from onCreate() and runs to onResume() repeating the setup from earlier
Is there a way to avoid that and have it not perform the loading twice? For example, ideally, the activity would know before even onCreate was called whether it should be landscape or portrait depending on some property of the launching intent, but unless I've missed something that isn't possible. I've managed to hack together a way to avoid repeating the loading by checking a boolean before the time-consuming loading steps, but that doesn't seem like the right way of doing it. I imagine I could override onSaveInstanceState, but that would require a lot of additional coding. Is there a simple way to do this?
Thanks!
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("image/jpeg");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "this is the test");
emailIntent.putExtra(Intent.EXTRA_TEXT, "testing time");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
I'm having some trouble with GSON, mainly deserializing from JSON to a POJO.
I have the following JSON:
{
"events":
[
{
"event":
{
"id": 628374485,
"title": "Developing for the Windows Phone"
}
},
{
"event":
{
"id": 765432,
"title": "Film Makers Meeting"
}
}
]
}
With the following POJO's ...
public class EventSearchResult {
private List<EventSearchEvent> events;
public List<EventSearchEvent> getEvents() {
return events;
}
}
public class EventSearchEvent {
private int id;
private String title;
public int getId() {
return id;
}
public String getTitle() {
return title;
}
}
... and I'm deserializing with the following code, where json input is the json above
Gson gson = new Gson();
return gson.fromJson(jsonInput, EventSearchResult.class);
However, I cannot get the list of events to populate correctly. The title and id are always null. I'm sure I'm missing something, but I'm not sure what. Any idea?
Thanks
My application takes userid from user as input, the userid is alphanumeric i.e just the first character is (a-z), other part is numeric. How can I validate input of this type ( like G34555) ?
I've looked up some answers but am not sure why mine is failing exactly...
The code looks something like this
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
String json = EntityUtils.toString(httpEntity);
//Convert to JsonArray
JSONArray jsonArray = new JSONArray(json);
Log.i(DEBUG_TAG, Integer.toString(jsonArray.length()));
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
Log.i(DEBUG_TAG, jsonObject.getString(KEY_ID));
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(KEY_ID, jsonObject.getString(KEY_ID));
map.put(KEY_TITLE, jsonObject.getString(KEY_TITLE));
map.put(KEY_ARTIST, jsonObject.getString(KEY_ARTIST));
map.put(KEY_DURATION, jsonObject.getString(KEY_DURATION));
map.put(KEY_VOTECOUNT, jsonObject.getString(KEY_VOTECOUNT));
map.put(KEY_THUMB_URL, jsonObject.getString(KEY_THUMB_URL));
map.put(KEY_GENRE, jsonObject.getString(KEY_GENRE));
//Adding map to ArrayList
if (Integer.parseInt(jsonObject.getString(KEY_VOTECOUNT)) == -1){
//If VoteCount is -1 then add to header
headerList.add(map);
}else {
songsList.add(map);
}
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
When I run logcat on String json, it seems to show correct info which is kind of like this...
{
"userdata": [
{
"id": "8",
"title": "Baby One More Time",
"artist": "Britney Spears",
"duration": "03:24:00",
"votes": "0",
"thumb_url": "http://api.androidhive.info/music/images/dido.png",
"genre": null
},
{
"id": "2",
"title": "As Long As You Love Me",
"artist": "Justin Bieber",
"duration": "05:26:00",
"votes": "0",
"thumb_url": "http://api.androidhive.info/music/images/enrique.png",
"genre": "Rock"
}
]
}
and the logcat on
JSONArray jsonArray = new JSONArray(json);
tells me that jsonArray.length()
10-31 22:57:28.433: W/CustomizedListView(26945): error! Invalid index
0, size is 0
Please let me know
Thank you,
I'm trying to implement filtering using ExpandableListView and SimpleCursorTreeAdapter (its subclass). How can I specify which data (maybe cursor field or TextView text) to use for filtering?
Thanks
Can anyone tell me how I can Dynamically add groups & children to an ExpandableListView. The purpose is to create a type of task list that I can add new items/groups to.
I can populate the view with pre-filled arrays but of course can't add to them to populate the list further. The other method i tried was using the SimpleExpandableListAdapter. Using this i am able to add groups from a List but when it comes to adding children i can only add 1 item per group.
public List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
public List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
public void addGroup(String group) {
Map curGroupMap = new HashMap();
groupData.add(curGroupMap);
curGroupMap.put(NAME, group);
//Add an empty child or else the app will crash when group is expanded.
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
Map<String, String> curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put(NAME, "EMPTY");
childData.add(children);
updateAdapter();
}
public void addChild(String child) {
List children = new ArrayList();
Map curChildMap = new HashMap();
children.add(curChildMap);
curChildMap.put(NAME, child);
curChildMap.put(IS_EVEN, "This child is even");
childData.add(activeGroup, children);
updateAdapter();
}
Hello,
I am creating an custom preference which contains an EditText.
The problem is when user clicks the EdiText for input suggestion box opens up and EditText looses focus. When EditText is clicked again for input, no problem occurs until 'blank space' is entered, which results in suggestion box and hence loss of focus.
What I mean by suggestion box is the box which pops up when entering text in EditText
I am very new to this, and I more looking for what information I need to study to be able to accomplish this.
What I want to do is use my GUI I have built for my app, but pull the information from a website.
If I have a website that looks like this:
(Sorry, can't post pics yet)
http://
dl.dropbox.com/u/7037695/ErrorCodeApp/FromWebsite.PNG
(full website can be seen at http://www.atmequipment.com/Error-Codes)
What would I need from the website so that if a user entered an error code here:
http://
dl.dropbox.com/u/7037695/ErrorCodeApp/InApp.PNG
It would use the search from the website, and populate the error description in my app?
I know this is a huge question, I'm just looking for what is actually needed to accomplish this, and then I can start researching from there. -- Or is it even possible?
For my AutoCompleteTextView I need to fetch the data from a webservice. As it can take a little time I do not want UI thread to be not responsive, so I need somehow to fetch the data in a separate thread. For example, while fetching data from SQLite DB, it is very easy done with CursorAdapter method - runQueryOnBackgroundThread. I was looking around to other adapters like ArrayAdapter, BaseAdapter, but could not find anything similar...
Is there an easy way how to achieve this? I cannot simply use ArrayAdapter directly, as the suggestions list is dynamic - I always fetch the suggestions list depending on user input, so it cannot be pre-fetched and cached for further use...
If someone could give some tips or examples on this topic - would be great!
hi
i am implementing registration form adding date field then click icon to display date dialog window then limit date validation in system date below date only how can implement the validation
protected Dialog onCreateDialog(int id)
{
Calendar c = Calendar.getInstance();
int cyear = c.get(Calendar.YEAR);
int cmonth = c.get(Calendar.MONTH);
int cday = c.get(Calendar.DAY_OF_MONTH);
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, mDateSetListener, cyear, cmonth, cday);
}
return null;
}
private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener()
{
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
{
String date_selected = String.valueOf(monthOfYear+1)+" /"+String.valueOf(dayOfMonth)+" /"+String.valueOf(year);
EditText birthday=(EditText) findViewById(R.id.EditTextBirthday);
birthday.setText(date_selected);
}
};
public void onClick(View v)
{
if(v == b1)
showDialog(DATE_DIALOG_ID);
}
}
**
showing in system date in below dates only how can implemented
some solution in running year to below years are display not incrementing above years this condition are appliying validations how can implemented ?
I would like to show a notification that displays the progress of an
ongoing operation. That works well for me.
But at the same time the remote view should contain cancel button to stop the ongoing operation. The usual content intent should still do something else, i.e. not cancel the ongoing operation. It seems though that I can only have one intent.
I have to specify a contentIntent that is launched when clicking on
the notification: If I don't specify that I get something along those
lines:
E/ActivityManager( 62): Activity Manager Crash
E/ActivityManager( 62): java.lang.IllegalArgumentException: contentIntent required ...
For the "cancel" button I set another intent:
Intent cancelSyncIntent = new Intent("com.xyz.CANCEL_SYNC");
contentView.setOnClickPendingIntent(R.id.cancel_sync,
PendingIntent.getBroadcast(context, 0,
cancelSyncIntent, 0));
But this never works. I always get the content intent when the button
is clicked. It looks like I cannot use buttons in remote views of
notifications?!
I could probably display a text: "<< Press to cancel operation ", but that seems rather heavy handed.
I made a Home application and I'd like to offer the ability to exit it and unset it as the default application.
Exit is easy (just starting an intent) but the problem is I don't want my program to be launched again the next time the user click the Home button.
I know that this can be done by going in the parameters / Applications / my app / erase default actions but I would like to do it from my program so that the user doesn't have to search this function.
How can it be done ?
Hi,
I am developing an application which is communicating with the server. Tha application can perform log-in and get different parameters from server.
The application consists of a RESTful client (custom class for making requests), Communication Service (the service which runs in the background) and the main activity.
For now I created multiple broadcast messages and multiple broadcast receivers in the main activity so when the application performs login operation a receiver (loginBroadcastReceiver) in the main activity receives a message and when another parameter is received from the server different message is broadcasted and another receiver handles the message.
This way however the application performance is poor but I am not sure whether it is due to multiple broadcast receivers.
Does anyone know what is the best way to exchange data between service and main activity - is it better to create a single broadcast receiver and retrieve all parameters from message or is it better to initialize multiple broadcast receivers for multiple parameters?
I would appreciate if you could provide any useful resource about the topic because I'm writing the thesis and it would be good if the solution could be explained.
While i'm clicking a button in my menu list (for example select all)my application is getting force closed.Why is it so???in eclipse emulator it is working fine,but in phone(i'm using LG620)it's getting force closed,as i've no cable with me,i can't debug it.
I was following the progress dialog example in the ApiDemos.
all went great except for one thing - I want to remove the numbers that appear underneath the bar (those running numbers that run from 0 to .getMax().
couldn't find how to do it.
anyone?
Ori
Hi
I defined a remote service over a AIDL file. Now i want to access this service in a different application. But how can I do that? The AIDL file is not accessible in my second application, and if i just copy the AIDL file, then the service can^^t be found.
Any hints for that problem??
Thanks Sebi