Search code examples
extendandroid

Extend Application in Android Why does not work?


I have a class which is extending Application

public class MyContext extends Application {

    private String _eposta;
    public String getEposta() 
    {
        return _eposta;
    }
    public void setEposta(String eposta) {
        _eposta = eposta;
    }

    private String _sifre;
    public String getSifre() 
    {
        return _sifre;
    }
    public void setSifre(String sifre) {
        _sifre = sifre;
    }

And I have a main Activity class

 eposta = epostaTxt.getText().toString();
    sifre = parolaTxt.getText().toString();
    ((MyContext)getApplication()).setEposta(eposta);
    ((MyContext)getApplication()).setEposta(sifre);

But on this line: ((MyContext)getApplication()).setEposta(eposta) application fall into the catch field.

By the way I declare the class into the manifest

<application android:name="com.mobil.eposta.MyContext"
                 android:icon="@drawable/ic_launcher"
                 android:label="@string/app_name">

Solution

  • don't do this:

    ((MyContext)getApplication()).setEposta(eposta)
    

    do this:

    MyContext.setEposta(eposta)
    

    should work =)