I’m creating an app. but now i want it to open a other app with a imagebutton. i searched google for like 5 days there are many awnsers but not the right one.
there are awnsers but not the full explaination.
i found this part
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.package.address","com.package.address.MainActivity"));
startActivity(intent);
but where do i have to put this so it works on my imagebutton. and what classes or things do i have to make.
This is my appactifity.java
package eu.cornholio.rom;
import android.app.Activity;
import android.os.Bundle;
public class CornholioROMActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
and this is my main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:gravity="center"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/cornh" android:contentDescription="@string/cornholio"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/cornholio" />
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/cwm" android:clickable="true" android:contentDescription="@string/cmw"/>
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/jkay"
android:clickable="true"
android:contentDescription="@string/jkay"/>
</LinearLayout>
here my code
package eu.cornholio.rom;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
public class CornholioROMActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//finding your image button
ImageButton btn = (ImageButton) findViewByid(R.id.imageButton1);
//setting onClick listener
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("eu.chainfire.cfroot.cwmmanager",
"eu.chainfire.cfroot.cwmmanager.MainActivity"));
startActivity(intent);
}
});
}
}
greetz drgekko
set onClickListener to your ImageButton.
Update
for example, if you want to set click action on
imageButton1, then you need to do the following changes in your onCreate method: