-1
public void doSomething(View view) {
    String url, link_url, pro;

    url = textIn.getText().toString();
    pro = spin.getSelectedItem().toString();
    c1 = new ConnectInternetClass(this);

    if (!url.isEmpty()) {
        if (url.contains(".") && !(url.contains(" "))) {
            if (url.split("\\.").length > 1) {
                if (checkConnection()) {

                    link_url = pro+url;
                    c1.execute(link_url);

                } else {
                    Toast.makeText(this, "check your internet connection", Toast.LENGTH_SHORT).show();
                    myText.setText("No Internet Connection");

                }
            } else {
                myText.setText("Unknown domain");
            }

        } else {
            myText.setText("Invalid URL");

        }

    } else {
        myText.setText("URL can\'t empty");
    }
}

I have that code to show a web page source. I want to show the result in another activity, but I don't know how. I use the create object from the first activity, but it's not method

public class ShowActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show);

        MainActivity ma = new MainActivity();
    }
Pang
  • 9,564
  • 146
  • 81
  • 122
MrH
  • 15
  • 6

2 Answers2

0

Why you use this kind of things. If you want to load a web page in an activity use webview for it. no need two activities to do that. Another way you can create a class which has your doSomething method (it should be public static) and call it from an activity by using that's class object. When you coding don't create unnecessary activities.

Roshan Maddumage
  • 130
  • 3
  • 12
  • okay sir, thank you for the advice, i will try to work on that, and not create unnecessary activities. – MrH Oct 31 '17 at 04:13
0

Passing data from a activity , linkUrl is your variable which data you want to pass :

Intent intent = new Intent (YourActivity.this, ShowActivity.class) ; 
intent.putExtra("KEY_LINK" , linkUrl);
startActivity(intent); 

Receiving data from ShowActivity , Access the data by the key in onCreate():

 String url = getIntent().getStringExtra("KEY_LINK"); 

Link : How do I pass data between Activities in Android application?

Link : https://developer.android.com/training/basics/firstapp/starting-activity.html

Piash Sarker
  • 466
  • 5
  • 21