[android-developers] Re: two threads, the main closes the DB but the second is still running and need to use the DB!

2009-01-22 Thread polo777

Dianne,

Thanks a lot for your answers. Really helpful!

Another question, just to make sure I understood what you meant:

 The main UI thread isn't destroyed.  Well, it is destroyed when the process
 is killed, and at that point it doesn't matter because the entire process is
 gone.

It means that any secondary threads is living within the process and
it is not a process by itself?

Thx,
polo

On Jan 21, 5:16 pm, Dianne Hackborn hack...@android.com wrote:
 On Wed, Jan 21, 2009 at 5:01 PM, polo777 polodr...@yahoo.com wrote:
  1 - What would be the life cycle of this class singleton if the user
  sends the application (and so the activity that was displayed) in the
  background and the activity is destroyed for instance?
  2 - How to make sure this singleton will stay alive as long as the
  secondary thread needs?

 If you want to have work happening while in the background without the
 system thinking you are just a background app and available to be killed,
 you need to start a Service and have the work associated with that.

  3 - I still don't really understand what happens when the secondary
  thread posts runnable toward the UI main thread that has been
  destroyed or sent to the background!

 The main UI thread isn't destroyed.  Well, it is destroyed when the process
 is killed, and at that point it doesn't matter because the entire process is
 gone.

 --
 Dianne Hackborn
 Android framework engineer
 hack...@android.com

 Note: please don't send private questions to me, as I don't have time to
 provide private support.  All such questions should be posted on public
 forums, where I and others can see and answer them.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] How to know which element of my list is selected when long click

2009-01-22 Thread polo777

Hi everyone,

I have a list using a customized BaseAdapter. When one element of the
list is hit during a long time, a contextual menu appears. I want to
use this one to delete or edit the selected item but I don't know how
to get id or anything else that could help me.

I tried getListView.getSelectedItem() thinking that it will give me
the object returned by the method getItem(int position) inherited in
my customized BaseAdapter. I got null.
When I tried getSelectedItemId(), I got -1.

Does someone have a solution?

Thanks a lot,
Polo

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: two threads, the main closes the DB but the second is still running and need to use the DB!

2009-01-21 Thread polo777

Another problem related to this one. When the secondary thread post
back to the main thread, the main thread fetches data from the DB and
update the view. Here also I got an error. It is perfectly normal
since the application has been killed. How to handle that?

Thanks a lot in advance.


On Jan 21, 2:45 pm, polo777 polodr...@yahoo.com wrote:
 Hi everyone,

 I have two threads:
 - the main one in charge of the UI
 - a second one that takes care of network calls, parsing responses and
 database updates.

 The main threads open the database, retrieves information into a
 Cursor that is used to feed a listView.

 My problem is the following: When I close the application the activity
 is destroyed, the second thread can still be running and thereby still
 can update the DB. Since the main thread open the DB, I want to close
 it to do the stuffs properly.

 However if I close it within the onDestroy method and if the second
 thread is running and is about to update the DB, I get an error.

 What is the best way to handle this situation?

 Thanks a lot
 Polo
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: two threads, the main closes the DB but the second is still running and need to use the DB!

2009-01-21 Thread polo777

Yes, I didn't think about that! That could definitely help me!
But in this case:

1 - What would be the life cycle of this class singleton if the user
sends the application (and so the activity that was displayed) in the
background and the activity is destroyed for instance?
2 - How to make sure this singleton will stay alive as long as the
secondary thread needs?
3 - I still don't really understand what happens when the secondary
thread posts runnable toward the UI main thread that has been
destroyed or sent to the background!

Thanks a lot for your answer,
It really helps me!

Polo

On Jan 21, 4:16 pm, Dianne Hackborn hack...@android.com wrote:
 I would recommend having a singleton that all of the clients go through,
 which takes care of keeping the database open as long as there are clients
 of it.



 On Wed, Jan 21, 2009 at 2:45 PM, polo777 polodr...@yahoo.com wrote:

  Hi everyone,

  I have two threads:
  - the main one in charge of the UI
  - a second one that takes care of network calls, parsing responses and
  database updates.

  The main threads open the database, retrieves information into a
  Cursor that is used to feed a listView.

  My problem is the following: When I close the application the activity
  is destroyed, the second thread can still be running and thereby still
  can update the DB. Since the main thread open the DB, I want to close
  it to do the stuffs properly.

  However if I close it within the onDestroy method and if the second
  thread is running and is about to update the DB, I get an error.

  What is the best way to handle this situation?

  Thanks a lot
  Polo

 --
 Dianne Hackborn
 Android framework engineer
 hack...@android.com

 Note: please don't send private questions to me, as I don't have time to
 provide private support.  All such questions should be posted on public
 forums, where I and others can see and answer them.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Activity goes to background but secondary thread needs to end its work

2008-12-17 Thread polo777

Hi Everyone,

I am currently working on an app that uses two threads: The first main
UI one and a secondary one that I use to retrieve some data from the
network, parse them and finally add them into a database.

My question is regarding to the lifecycle of my thread. The problem is
simple, I need the thread to end the work it is doing.

The user can close the activity or send it to the background at
anytime which is not a problem for the main thread that take cares of
the UI but the  secondary thread is still running and can be killed at
anytime stopping its work in a way that we don't control anything
(could be working on the database, parsing...).

What is the best solution to handle this problem?

Thanks a lot in advance.
Polo

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Activity goes to background but secondary thread needs to end its work

2008-12-17 Thread polo777

Ok thanks for your answer. I am going to investigate in this way.
However, according to my understanding, even though the service will
have a longer life time than the thread, it still can be killed. Then,
for a real safe mechanism I guess I have to take care of the problem
differently meaning perhaps changing  the nature of my code.





On Dec 17, 4:06 pm, Al alcapw...@googlemail.com wrote:
 You could create a service for the background task. Create your main
 Activity, call startService(), inside the service, create a
 thread, finish your work, then call stopSelf() to stop your service.
 Have a look 
 athttp://code.google.com/android/reference/android/app/Service.html.
 Services usually last longer and killed later then usual activities
 when memory is low.

 On Dec 17, 11:47 pm, polo777 polodr...@yahoo.com wrote:

  Hi Everyone,

  I am currently working on an app that uses two threads: The first main
  UI one and a secondary one that I use to retrieve some data from the
  network, parse them and finally add them into a database.

  My question is regarding to the lifecycle of my thread. The problem is
  simple, I need the thread to end the work it is doing.

  The user can close the activity or send it to the background at
  anytime which is not a problem for the main thread that take cares of
  the UI but the  secondary thread is still running and can be killed at
  anytime stopping its work in a way that we don't control anything
  (could be working on the database, parsing...).

  What is the best solution to handle this problem?

  Thanks a lot in advance.
  Polo
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Issues: Webview.loadData() trying to load a string created from a read file(asset) and a string

2008-11-25 Thread polo777

Hi,

Finally I created the content provider overriding the openFile method
so that I can use loadUrl() but still a part of the Javascript (of the
page loaded) that worked when it was loading from the web or an asset
file doesn't work here. I got a WebCore error telling me there is a
parsing issue!!! The content is exactly the same. Looks like the
WebKit doesn't work the same whether the file is an asset, page loaded
from Network or a string or a text from a file (ContentProvider
solution).
This problem drives me crazy!

Polo



On Nov 21, 4:56 pm, polo777 [EMAIL PROTECTED] wrote:
 I am gonna give a try and let you know. Thanks Mark!

 On Nov 21, 4:45 pm, Mark Murphy [EMAIL PROTECTED] wrote:

  polo777 wrote:
   After having tried to use addJavascriptInterface, I start working on
   the ContentProvider-based solution that you described.
   With this solution can I just create/open/read/delete a file in which
   I would store my string (javascript + html) so that I could use
   loadUrl or loadDataWithBaseURL properly using the url content://
   blabla.provider?

  In theory, yes. I haven't tried it myself, though I should be giving
  that a shot sometime next week, I think. I've seen other posts on these
  lists that suggest others have it working, though it is not exactly trivial.

  --
  Mark Murphy (a Commons Guy)http://commonsware.com

  Android Training on the Ranch! -- Mar 16-20, 
  2009http://www.bignerdranch.com/schedule.shtml


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Content Provider: create/open a file in the overrided openFile function

2008-11-24 Thread polo777

Hello Everyone,

I am trying to override the openFile function of a contentProvider so
that I can use the URI in the loadURL function. The following code is
really spread on the forum but nobody seems to meet any problems on
this line File file = new File(...).
As far as I am concerned, I got a FileNotFoundException and I really
dont understand why!

If anyone has an idea that would be great.
Thanks in advance
Polo


private static final String file_path = file:///data/data/
com.android.orange.myApp/files;
private static final String file_name = HtmlView;

@Override
public ParcelFileDescriptor openFile(Uri uri, String mode)
{
try
{
mDbH.open();
// content that I want to add in my file
Cursor c = mDbH.fetchContent();
String content = c.getString(c.getColumnIndex
(DbAdapter.KEY_WEBVIEW_CONTENT));
c.close();
mDbH.close();
//
File file = new File(file_path,file_name);
FileWriter out;

out = new FileWriter(file);
out.write(  );
out.close();
}

   catch (FileNotFoundException ex)
{
// Checked for file existance already, so this should
not happen
return null;
}
catch (IOException ex)
{
// read or close failed
return null;
}

int m = ParcelFileDescriptor.MODE_READ_ONLY;

if (mode.equalsIgnoreCase(rw))
m = ParcelFileDescriptor.MODE_READ_WRITE;

if (file.canRead())
{
ParcelFileDescriptor pfd = 
ParcelFileDescriptor.open(file, m);
}

ParcelFileDescriptor pfd = ParcelFileDescriptor.open(file, m);
return pfd;

}
catch (FileNotFoundException e)
{

}
return null;
}
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Issues: Webview.loadData() trying to load a string created from a read file(asset) and a string

2008-11-21 Thread polo777

Hi Everyone,

I want to display into a WebView the concatenation of a string and the
content of a file located in my asset.
With the code below, when I display the string in my log it looks
perfect but when I launch the activity I just get the following
message:  Web page not available the web page at data:text/html;utf-8
and then the content of my string/page escaped... might be temporarly
down or it may have moved permanently ro a new web address.


InputStreamReader is = new 
InputStreamReader(getAssets().open
(header.html));
//
BufferedReader buff = new BufferedReader(is);
//
StringBuffer out = new StringBuffer();
//
String strLine = null;
//
while ((strLine = buff.readLine()) != null)
{
out.append(strLine);
}
//
is.close();

String mimeType = text/html;
String encoding = utf-8;

String fin = new String(out.toString());

mWebView.loadData(fin, mimeType, encoding);


Does someone have a solution? That would be great.

Thanks a lot in advance.
polo


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Issues: Webview.loadData() trying to load a string created from a read file(asset) and a string

2008-11-21 Thread polo777

Re,

Actually, I still have a problem.
When I use this trick, the javascript containing in my page doesn't
work whereas the same page(html/javascript) works when I load it from
the network or from a file:///android_asset/myfile.html.

Anything?

Polo

On Nov 21, 1:06 pm, polo777 [EMAIL PROTECTED] wrote:
 Thanks a lot of Mark.

 This workaround did the trick.

  String mimeType = text/html;
  String encoding = utf-8;
  mWebView.loadDataWithBaseURL(fake://fake.com, out.toString(),
 mimeType, encoding, null);

 Regards,
 Polo

 On Nov 21, 11:42 am, Mark Murphy [EMAIL PROTECTED] wrote:

  polo777 wrote:
   Does someone have a solution? That would be great.

  Use loadDataWithBaseURL(), even if you have to pass in a fake URL.

  --
  Mark Murphy (a Commons Guy)http://commonsware.com

  Android Training on the Ranch! -- Mar 16-20, 
  2009http://www.bignerdranch.com/schedule.shtml


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Issues: Webview.loadData() trying to load a string created from a read file(asset) and a string

2008-11-21 Thread polo777

Hi Mark,

First thanks a lot for your answers...

After having tried to use addJavascriptInterface, I start working on
the ContentProvider-based solution that you described.
With this solution can I just create/open/read/delete a file in which
I would store my string (javascript + html) so that I could use
loadUrl or loadDataWithBaseURL properly using the url content://
blabla.provider?

I am not sure exactly how to proceed.

Thanks
Polo

On Nov 21, 4:26 pm, Mark Murphy [EMAIL PROTECTED] wrote:
 polo777 wrote:
  Re,

  Actually, I still have a problem.
  When I use this trick, the javascript containing in my page doesn't
  work whereas the same page(html/javascript) works when I load it from
  the network or from a file:///android_asset/myfile.html.

  Anything?

 Your simple options are:

 1. Instead of your fake base URL, use a real network URL pointing to the
 spot where the Javascript, images, and other stuff lives. Of course,
 this will require a network connection to work. You may wish to also
 supply your WebView with a WebViewClient implementation, so you can hook
 shouldOverrideUrlLoading() to determine if a given clicked-upon link
 should go to the Internet or should be loaded from your
 locally-generated content.

 2. Don't use WebView for locally-generated material.

 Your more complicated options include building a ContentProvider for
 serving your HTML, Javascript, and whatnot, and using the appropriate
 content: URL to load it.

 In general, Android makes it rather difficult for one to support
 locally-hosted Web content.

 --
 Mark Murphy (a Commons Guy)http://commonsware.com

 Android Training on the Ranch! -- Mar 16-20, 
 2009http://www.bignerdranch.com/schedule.shtml
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Issues: Webview.loadData() trying to load a string created from a read file(asset) and a string

2008-11-21 Thread polo777

I am gonna give a try and let you know. Thanks Mark!


On Nov 21, 4:45 pm, Mark Murphy [EMAIL PROTECTED] wrote:
 polo777 wrote:
  After having tried to use addJavascriptInterface, I start working on
  the ContentProvider-based solution that you described.
  With this solution can I just create/open/read/delete a file in which
  I would store my string (javascript + html) so that I could use
  loadUrl or loadDataWithBaseURL properly using the url content://
  blabla.provider?

 In theory, yes. I haven't tried it myself, though I should be giving
 that a shot sometime next week, I think. I've seen other posts on these
 lists that suggest others have it working, though it is not exactly trivial.

 --
 Mark Murphy (a Commons Guy)http://commonsware.com

 Android Training on the Ranch! -- Mar 16-20, 
 2009http://www.bignerdranch.com/schedule.shtml
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Extend a EditText to create an editable view performing operation onKeyDown

2008-11-06 Thread polo777

Hi Everyone,

I am trying desperately to extend the EditText view to override
onKeyDown. My goal is to create an EditText that will update UI
elements each time the user will type one character within.

The code is as simple as that:

public class SearchView extends EditText
{
public SearchView(Context context)
{
super(context);
}

 @Override
 public boolean onKeyDown(int keyCode, KeyEvent event)
 {
 // the code (right now nothing)
 return true;
 }
}

The main package is com.android.polo.myApp
It is located in the package com.android.polo.myApp.view

Here is the View.xml using this new view:

LinearLayout xmlns:android=http://schemas.android.com/apk/res/
android
android:orientation=horizontal
android:layout_width=fill_parent
android:layout_height=wrap_content

com.android.polo.myApp.view.SearchView
android:id=@+id/searchTextView
android:layout_width=fill_parent
android:layout_height=wrap_content/

/LinearLayout

I got this error:

11-06 19:00:21.555: ERROR/AndroidRuntime(1207):
java.lang.RuntimeException: Unable to start activity
ComponentInfo.. android.view.InflateException: Binary XML file
line #28: Error inflating class com.android.polo.myApp.view.SearchView

11-06 19:00:21.555: ERROR/AndroidRuntime(1207): Caused by:
android.view.InflateException: Binary XML file line #28: Error
inflating class com.android.polo.MyApp.view.SearchView
..
11-06 19:00:21.555: ERROR/AndroidRuntime(1207): Caused by:
java.lang.NoSuchMethodException: SearchView

Thanks a lot in advance
Polo

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: SharedPreferences: editor.commit() always false even though it commits

2008-11-05 Thread polo777

Hi Jason,

Thanks a lot for your answer.

Regarding the security stuff, I created a md5 function that I apply on
the password to then store it within the preferences file. As you
said, at least it won't be stored plaintext.

Again, thank you
Bye




On Nov 4, 11:23 pm, Jason Parekh [EMAIL PROTECTED] wrote:
 Yup, the returning of false was a bug and you'll find it fixed in a future
 update.

 Re: storing credentials.  Is there any way you can get by without storing
 the actual password?  Perhaps use the password to get some token from the
 service?  If you absolutely have to store the password, I'd suggest at least
 encrypting it with a key that's hard coded in your app (yes, this is still
 not secure, but at least it won't be stored plaintext).

 jason

 On Tue, Nov 4, 2008 at 1:51 PM, polo777 [EMAIL PROTECTED] wrote:

  Hi everyone,

  Almost everything is in the title. I am trying to save username and
  password into the sharedpreferences file. I used the little function
  below to do so:
  Everything works (The data are written correctly, I can read them
  afterward) but the editor.commit() always returns false even though
  the commit works(). Is that a bug?

         private void saveCredential(String username, String password)
         {
                 // Restore or Create preferences if it doesn't exist
                 SharedPreferences settings =
  getSharedPreferences(Common.PREFS_NAME,
  MODE_PRIVATE);
                 // We need an Editor object to make changes in the
  preferences file
                 SharedPreferences.Editor editor = settings.edit();
                 // Then we add the login and the password
                 editor.putString(Common.PREF_USERNAME,username);
                 editor.putString(Common.PREF_PASSWORD,password);
                 // We don't forget to commit our edits
                 if (editor.commit())
                          Log.v(DEBUG_TAG, (Username:  + username + ) ;
  (password :  + password + ) correctly added into file  +
  Common.PREFS_NAME);
                else
                        // not good
         }

  If anyone has a solution, an answer, anything, that would be great ;)

  Also in term of security, is that fine? Should I store the credential
  into a database or anything else?

  Thanks a lot.
  Polo



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] SharedPreferences: editor.commit() always false even though it commits

2008-11-04 Thread polo777

Hi everyone,

Almost everything is in the title. I am trying to save username and
password into the sharedpreferences file. I used the little function
below to do so:
Everything works (The data are written correctly, I can read them
afterward) but the editor.commit() always returns false even though
the commit works(). Is that a bug?

private void saveCredential(String username, String password)
{
// Restore or Create preferences if it doesn't exist
SharedPreferences settings = 
getSharedPreferences(Common.PREFS_NAME,
MODE_PRIVATE);
// We need an Editor object to make changes in the preferences 
file
SharedPreferences.Editor editor = settings.edit();
// Then we add the login and the password
editor.putString(Common.PREF_USERNAME,username);
editor.putString(Common.PREF_PASSWORD,password);
// We don't forget to commit our edits
if (editor.commit())
 Log.v(DEBUG_TAG, (Username:  + username + ) ;
(password :  + password + ) correctly added into file  +
Common.PREFS_NAME);
   else
   // not good
}

If anyone has a solution, an answer, anything, that would be great ;)

Also in term of security, is that fine? Should I store the credential
into a database or anything else?

Thanks a lot.
Polo

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---