I know here exists a lot of topics with this header but I am new on android developing and tried many things but don't reach a solution.
I have a MainClass with a TextView. The MainClass calls a Method in a second Class ("Check"). The second Class should only create an intent with a string which i print out in textview of the mainClass. (Later it should be more complex but first I have to get that).
Here my Code of MainClass:
package com.projektarbeit;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
public static TextView output = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Variable initialisieren
output = (TextView) findViewById(R.id.output);
//App gestartet ausgeben
output.setText("App started");
Check check1 = new Check();
check1.doCheck();
Intent intent = getIntent();
String myString = intent.getStringExtra("Test");
output.setText(myString);
}
}
Here my Code of CheckClass:
package com.projektarbeit;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class Check extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_check);
}
public void doCheck (){
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra("Test", "This is a test");
startActivity(intent);
}
}
Am I totally wrong or what is my mistake?