This is a mirror of official site: http://jasper-net.blogspot.com/

Android for .NET Developers - Creating Files

| Tuesday, August 23, 2011
The Android for .NET Developers Series
Part 1 Starting with this article, I'll discuss what you need to know to approach Android programming without any aid from your .NET expertise.
Part 2 In this article, we'll go through an Android application that accepts input from the user and handles user's clicking.
Part 3 In this article, you will learn how to build the user interface.
Part 4 In this article, I'll be delving deep into menus and dialog boxes in Android for .NET, and discuss a few very common (and frequently used) types of menus and dialogs.
Part 5 In this article, Dino Esposito focuses on the options that the Android SDK offers for local storage.
Part 6 In this article, Dino Esposito shows how to build settings dialog boxes using a built-in feature of Android for .NET.
Part 7 In this article, I'll dissect the code of a realistic application - a waterpolo score manager - to show how to save and resume the status of a game using both the internal storage and SD card.


Introduction

Any serious mobile application will use the local storage to persist as much data as possible thus enabling offline working and occasionally connected scenarios. The extent at which this is really possible varies with the goals of the application. Nearly any application, however, can take some advantage of some working data saved locally. In general, an Android mobile device offers two options for storage - phone internal storage and external SD cards. The internal phone storage is limited and not expandable; an SD card can be replaced as needed. This is the common scenario you face with Android; in the iPhone space, for example, external cards are not supported. In Windows Phone 7, only a few devices allow you to add an external card which can't be ported to other types of phone after use.

This distinction between internal and external storage is important because in Android you need to use a slightly different API to read and write files in both locations. More, the internal storage that is left to user applications is tiny space in the order of 100MB for most devices. (I have an HTC Desire, but I've heard similar stories for devices of the same class.) In this article, I'll dissect the code of a realistic application - a waterpolo score manager - to show how to save and resume the status of a game using both the internal storage and SD card.


Creating Files in the Internal Storage

Each Android application gains access to the internal storage through a bunch of functions exposed as part of the application context. The storage is generally considered private of the application and will be removed when you uninstall the application or when you choose to clear the data of the application through the interface of the phone's maintenance application. The Android API for preferences saves data to the internal storage and this data is removed when you clean/uninstall the application.

The simplest way to create a file in the private area is shown below:

FileOutputStream fos = openFileOutput(filename, Context.MODE_PRIVATE);

Read more: dot net Slackers
QR: Android-for-NET-Developers-Creating-Files.aspx

Posted via email from Jasper-net

0 comments: