Lifetime of an app's Context object

by Jin Chiu » Tue, 20 Jul 2010 08:30:35 GMT


Sponsored Links
 What is the lifetime of an app's global android.content.Context
object? Does it last until the last component of the app is terminated
by the Android runtime?

--



Lifetime of an app's Context object

by stephan » Wed, 21 Jul 2010 00:16:22 GMT


 I whould definitely expect that. Anyway you need a reference to the
Context object if you like access it. As long as that reference exists
the context exist.

Stephan

--


Sponsored Links


Other Threads

1. Instrumentation on the virtual keyboard.

Hello devs,

I'm using Intrumentation to invoke keystrokes and mouse events, but I
have a problem when trying to do so on the virtual keyboard. If the
virtual keyboard pops up and I want to send a mouse event to click on
a character of the keyboard, I get that error/warning in the console:

W/WindowManager(  586): Permission denied: injecting pointer event
from pid 1580 uid 10020 to window Window{437522d0 InputMethod
paused=false} owned by uid 10003

Is there a way to make it work? I know I can't do instrumentation on
native activites, does the native keyboard acts like a native
activity?

Thanks.
--~--~---------~--~----~------------~-------~--~----~

2. Problem :can't read a file, can't comunicate with a server

Hi guys, I've some problems:

1)first I'm not able to read  a file:(
2)second seems that my code that have to simulate a Client can't
connect to my server.
maybe I'm wrong something, Ip address(I think it is right)? I have set
the virtual device on port 5554 (the default)..I need to redirect the
host port?
this is my code:


;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import java.io.*;
import java.net.*;
import java.util.NoSuchElementException;
import java.util.Scanner;



public class C extends Activity {
    /** Called when the activity is first created. */
        private PrintWriter savedpoint;
        private Context context = this;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        try{

        savedpoint = new PrintWriter(openFileOutput
("Data.dat",MODE_APPEND));


        for(int i=0;i<20;i++)//scrive coordinate
        {
                savedpoint.println(-78.443221+"i"+" "+120.344423+"i");

        }

        F thread=new F(getFilesDir(),this);
        thread.start();

        }catch (FileNotFoundException e) {
                        e.printStackTrace();
                }
    }
}

//thread that have to acess to the server
class F extends Thread{
        File directory;
        Context context;

        private final static String host = "10.0.2.2";
        private final static int port = 2120;


        F(File directory,Context context)
{this.directory=directory;this.context=context;}
        public void run()
        {

                try{

                Socket socket = null;
                PrintWriter out = null;
                InetAddress ip = InetAddress.getByName(host);
                socket = new Socket(ip,port);       ----->SEEMS THERE IS NO
CONNECTIONS, BECAUSE THE SERVER DOESN'T SIGN ANYTHING
                out = new PrintWriter( new BufferedWriter( new 
OutputStreamWriter
(socket.getOutputStream())),true);
                Scanner s=new Scanner(directory+"Data.dat");     ---> The right 
way?

                try {
                        while (true) {

                                String l = s.nextLine();    ---->ERROR
                                out.println(l);
                        }
                } catch (NoSuchElementException e) {s.close();
                out.println("*");
                }//catch(FileNotFoundException e){}
                } catch (UnknownHostException e) {
                        e.printStackTrace();
                } catch (IOException e) {
                        e.printStackTrace();}
}
}

the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="prova.client"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/
app_name">
        <activity android:name=".C"
                  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-sdk android:minSdkVersion="3" />
</manifest>


thanks in advance for any help..

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

3. Failed to find provider info for com.google.settings

4. Android on Motorola A810?

5. Using custom _init and _fini on Android ARM

6. dirent64 is missing in bionic/libc/kernel/common/linux/dirent.

7. MPEG2 TS + HTTP Live Streaming Support on Android