private file last modified date

by Dson » Sun, 01 Aug 2010 13:06:35 GMT


Sponsored Links
 Hi Guys,

 I am trying to get the last modified date of an internal file and it
always returns me 0 although I could read the file properly. Can you
please let me know if I am doing anything wrong...

Creating a file...
--------------------

FileOutputStream Os = activity.openFileOutput("file1.jpg",
Context.MODE_PRIVATE);
cachedImage.compress(CompressFormat.JPEG, 75, Os);
Os.close();


Reading the file...
--------------------
long mod_time = 0;
File file = new File("file1".jpg");
mod_time = file.lastModified();
FileInputStream Is = activity.openFileInput("file1.jpg");
cachedImage = BitmapFactory.decodeStream(Is);
Is.close();


**mod_time is always zero!!!!**

--



private file last modified date

by Mark Murphy » Sun, 01 Aug 2010 14:53:33 GMT


 


That is because you are looking at the wrong file. Use new
File(getFilesDir(), "file1.jpg") to get at the same file that you use
with openFileInput()/openFileOutput().

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://github.com/commonsguy 
 http://commonsware.com/blog  |  http://twitter.com/commonsguy 

Android Training...At Your Office:  http://commonsware.com/training 

--


Sponsored Links


Other Threads

1. Need help with Activity stack (How to start a new Activity from an Overlay)

Hi all

I'm stuck on a tought problem that's been kepeing me busy for a couple
of days :

I have a MapActivity wich is using an Overlay.
The overlay is  instanciated like this in the MapActivity

               mPickDriverOverlay=new
PickDriverOverlay(this,rideRequests,myMapView);
                myMapView.getOverlays().add(mPickDriverOverlay);

On this Overlay , i'm listening for onKeydown and when the center of
the dpad is pushed , i'm trying to start a new Activity:

                Intent intent=new
Intent(activity,AskDriverForARideActivity.class);
                activity.startActivity(intent);

My problem is that this activity is launched but not displayed : i can
see that in the logs :

11-10 16:09:27.564: VERBOSE/PickDriverOverlay(1096): Adding a new
Overlay with 1 rides founds
11-10 16:09:34.174: WARN/KeyCharacterMap(1096): No keyboard for id 0
11-10 16:09:34.189: WARN/KeyCharacterMap(1096): Using default keymap: /
system/usr/keychars/qwerty.kcm.bin
11-10 16:09:34.193: VERBOSE/PickDriverOverlay(1096): KEY Down :23
11-10 16:09:34.284: INFO/ActivityManager(53): Starting activity:
Intent { comp={com.piggyBack/
com.piggyBack.activities.AskDriverForARideActivity} (has extras) }
11-10 16:09:34.354: VERBOSE/RideActivity(1096): onPause
11-10 16:09:34.484: VERBOSE/AskDriverForARideActivity(1096): onCreate
11-10 16:09:34.874: VERBOSE/AskDriverForARideActivity(1096): onResume

so , i can see the first activity beeing paused and the new one
started , but nothing is displayed on the screen.

if i'm pushing again the key , i have this log :

11-10 16:11:39.084: VERBOSE/PickDriverOverlay(1096): KEY Down :23
11-10 16:11:39.173: INFO/ActivityManager(53): Starting activity:
Intent { comp={com.piggyBack/
com.piggyBack.activities.AskDriverForARideActivity} (has extras) }
11-10 16:11:39.203: VERBOSE/AskDriverForARideActivity(1096): onPause
11-10 16:11:39.244: VERBOSE/AskDriverForARideActivity(1096): onCreate
11-10 16:11:39.524: VERBOSE/AskDriverForARideActivity(1096): onResume

but this time , the view is displayed

when i'm trying to close the application , i can see that the view was
hiden behind the map view.

I've been trying a lot of things like setting the Flags
FLAG_ACTIVITY_NEW_TASK,
FLAG_ACTIVITY_BROUGHT_TO_FRONT
trying to call the makeActive() method in the new Activity,...

Does anyone see what's wrong with or how to solve this and how tu put
an Activity on the top of the stack (from the doc , a new Activity
should start on the top?

Thanks

Chris




--~--~---------~--~----~------------~-------~--~----~

2. Excessive JNI global references

Hi Guys
   I am trying to build build a file download service which makes
makes http connection and
                inStream = httpConnection.getInputStream();
                outStream = new FileOutputStream(tempFile);
                byte buf[] = new byte[58*1024];
                do
                {

                    numread = inStream.read(buf, 0, 58*1024);
                    if (numread == -1)
                        break;
                    outStream.write(buf, 0, numread);
                }
                while (true);

but sometimes it crashes giving error :Excessive JNI global
references: ( Pl. see logs below )

let me know if you have some ideas

--Ash


D/dalvikvm(   53): GC freed 1217 objects / 50416 bytes in 174ms
D/dalvikvm(  440): GREF has increased to 2001
W/dalvikvm(  440): Last 10 entries in JNI global reference table:
W/dalvikvm(  440):  1991: 0x4352afa0 cls=Ljava/lang/ref/WeakReference;
(28 bytes)
W/dalvikvm(  440):  1992: 0x4352b018 cls=Ljava/lang/ref/WeakReference;
(28 bytes)
W/dalvikvm(  440):  1993: 0x4352b8e0 cls=Landroid/database/
ContentObserver$Transport; (28 bytes)
W/dalvikvm(  440):  1994: 0x4352b900 cls=Landroid/database/
CursorToBulkCursorAdaptor; (44 bytes)
W/dalvikvm(  440):  1995: 0x4352b900 cls=Landroid/database/
CursorToBulkCursorAdaptor; (44 bytes)
W/dalvikvm(  440):  1996: 0x4352bb78 cls=Ljava/lang/ref/WeakReference;
(28 bytes)
W/dalvikvm(  440):  1997: 0x4352bbf0 cls=Ljava/lang/ref/WeakReference;
(28 bytes)
W/dalvikvm(  440):  1998: 0x4352c658 cls=Landroid/database/
ContentObserver$Transport; (28 bytes)
W/dalvikvm(  440):  1999: 0x4352c678 cls=Landroid/database/
CursorToBulkCursorAdaptor; (44 bytes)
W/dalvikvm(  440):  2000: 0x4352c678 cls=Landroid/database/
CursorToBulkCursorAdaptor; (44 bytes)
W/dalvikvm(  440): JNI global reference table summary (2001 entries):
W/dalvikvm(  440):    53 of Ljava/lang/Class; 164B (42 unique)
W/dalvikvm(  440):     1 of Ljava/lang/String; 28B
W/dalvikvm(  440):   941 of Ljava/lang/ref/WeakReference; 28B (941
unique)
W/dalvikvm(  440):    10 of Ljava/lang/ref/WeakReference; 36B (10
unique)
W/dalvikvm(  440):     1 of Ldalvik/system/VMRuntime; 12B
W/dalvikvm(  440):     1 of Landroid/app/ActivityThread
$ProviderRecord; 28B
W/dalvikvm(  440):     1 of Landroid/app/ActivityThread
$ApplicationThread; 28B
W/dalvikvm(  440):     1 of Landroid/content/ContentProvider
$Transport; 28B
W/dalvikvm(  440):   470 of Landroid/database/ContentObserver
$Transport; 28B (470 unique)
W/dalvikvm(  440):     2 of Landroid/database/ContentObserver
$Transport; 36B (2 unique)
W/dalvikvm(  440):   497 of Landroid/database/
CursorToBulkCursorAdaptor; 44B (451 unique)
W/dalvikvm(  440):    23 of Landroid/database/
CursorToBulkCursorAdaptor; 52B (21 unique)
W/dalvikvm(  440): Memory held directly by native code is 67888 bytes
E/dalvikvm(  440): Excessive JNI global references (2001)
E/dalvikvm(  440): VM aborting
I/DEBUG   (   21): *** *** *** *** *** *** *** *** *** *** *** *** ***
*** *** ***

--~--~---------~--~----~------------~-------~--~----~

3. Example how to handle dial in and dial out events...

4. GMail App Suggestion

5. repo init

6. Menus In Dialogs

7. Cookie not enabled while using HttpPOST