on android. my activity is like this.
public class MainActivity extends Activity {
static TextView textview;
static int aaa = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
setContentView(R.layout.activity_main);
textview = (TextView)findViewById(R.id.textView6);
//other method,startservice()and so on.
and there is BroadcastReceiver to receive a flag from service.
public static class Receiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intents) {
intents.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
textview.setText("set")//throw null point
Log.d("aaa","aaa is" + aaa);
like this, in onReceiver, textview is null. as test, int aaa is'nt null.
why textview is null?
EDIT Texttiew xml is
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/adview"
android:layout_alignParentLeft="true"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
And method in Activity using same textview.settext isnt null. Thanks.
EDIT2 I can know i should save this variable. So, whats the best way to save VIEW variable? SharedPreferences seem not able to save VIEW variable.