Android MultiScreen Intent Issue - android

I devised some activities with its relationships between each other after I pass any acttivity from Main Actvity. But I couldn't succeed to pass another activity from any activity.
Here is the code below.
public class A extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_istanbul);
TextView attractivePlaces = (TextView) findViewById(R.id.a_category_attractive_places);
attractivePlaces.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"A",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(A.this,B.class); // Here the issue is.
startActivity(intent);
}
});
}
}
How can I solve the problem.

Try changing View.OnClickListener() to TextView.OnClickListener()
final code would be like this:
public class A extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_istanbul);
TextView attractivePlaces = (TextView) findViewById(R.id.a_category_attractive_places);
attractivePlaces.setOnClickListener(new TextView.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"A",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(A.this,B.class); // Here the issue is.
startActivity(intent);
}
});
}
}
Maybe this will help.

Related

How to check which algorithm i am used in my program

I download bike car service app from tech vidvan but i don't know which algorithm use in this program so how to i check it. Please check below program this is Main Activity.
public class MainActivity extends AppCompatActivity {
Button btn_vehicleOwner, btn_serviceCentre;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_serviceCentre = findViewById(R.id.btn_serviceCentre);
btn_vehicleOwner = findViewById(R.id.btn_vehicleOwner);
btn_serviceCentre.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, ServiceLogin.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
}
});
btn_vehicleOwner.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, UserLogin.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
}
Which algorithm i am use in this program?

Android Intent / Start Activity Issue

I'm having an Issue that I have two Activities A and B when I clicked on Button to change an Activity from A to B . It Restart my Application I don't know what going wrong Please help me
public class Login_Choice_Activity extends AppCompatActivity{
private Button d_btn,p_btn;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login__choice);
FindAllView();
p_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// startActivity(new
Intent(Login_Choice_Activity.this,Patient_SignIn_Activity.class));
Toast.makeText(getApplicationContext(),"CLICKED",Toast.LENGTH_LONG).show();
}
});
}
private void FindAllView(){
d_btn = findViewById(R.id.choice_doctor_btn);
p_btn = findViewById(R.id.choice_patient_btn);
}
}
https://i.stack.imgur.com/KcgAh.gif
It could be better if you create a method for opening the new Activity and call it from onClick(View v) method. Example
private void openActivity() {
startActivity(new Intent(this,Patient_SignIn_Activity.class));
}
In your onClick call:
#Override
public void onClick(View v) {
openActivity()
}

is there any body know my button is not working for go on next page on android studio

public class MainActivity extends AppCompatActivity {
private Button c;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
c = (Button)findViewById(R.id.buttonRegister1);
c.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent j = new Intent(MainActivity.this,Welcome.class);
}
});
}
}
You should call
startActivity(j);
you forgot a simple thing :-
c.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent j = new Intent(MainActivity.this,Welcome.class);
startActivity(j);
}
});

How can I make a button invisible if and only if its activity intented from another activity?

I want to make a button in an activity disabled if it is intented from a certain button and otherwise enabled if and it is intented from some other class.What I am saying will be clear after reading the code.
This is the function to intent the class containing the button.
showperson.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
falses=true;
ob.truth=false;
Toast.makeText(home_page.this, "doneit"+ob.truth, Toast.LENGTH_SHORT).show();
// Button clik=fb.getButton();
// clik.setVisibility(View.GONE);
Intent to=new Intent(home_page.this,Form.class);
to.putExtra("buttonclik",false);
startActivity(to);
}
});
Try to add this in onCreate():
Intent intent = getIntent();
if (intent != null) {
boolean isButtonClicked = intent.getBooleanExtra("buttonclik", false);
if (isButtonClicked) {
showperson.setEnabled(false);
}
}
And change false to true at to.putExtra("buttonclik",false);
You can achieve that by setting a flag from the caller activity. Refer to the example below.
public class ActivityA extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_a);
Intent intent = new Intent(this, ActivityThatContainsTheButton.class);
intent.putExtra("activity", "activityA");
startActivity(intent);
}
}
public class ActivityB extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_b);
Intent intent = new Intent(this, ActivityThatContainsTheButton.class);
intent.putExtra("activity", "activityB");
startActivity(intent);
}
}
public class ActivityThatContainsTheButton extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_x);
Button button = findViewById(R.id.button);
String from = getIntent().getStringExtra("activity");
if (from != null) {
if (from.equals("activityA")) {
button.setVisibility(View.VISIBLE);
} else if (from.equals("activityB")) {
button.setVisibility(View.INVISIBLE);
}
}
}
}

How do I open a button another activity with another button?

I have made successfully my Imagebutton to open anther activity but the issue is by using the same method on another ImageButton it comes up with an error saying the method is already used in "Main Activity".
public class MainActivity extends ActionBarActivity {
private static ImageButton ImageButton_sbm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OnClickImageButtonListener();
}
public void OnClickImageButtonListener() {
ImageButton_sbm = (ImageButton)findViewById(R.id.imageButton);
ImageButton_sbm.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("saintbedeslytham.saintbedes.event");
startActivity(intent);
}
}
);
}
private static ImageButton ImageButton2_sbm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OnClickImageButtonListener();
}
public void OnClickImageButtonListener() {
ImageButton_sbm = (ImageButton)findViewById(R.id.imageButton2);
ImageButton_sbm.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("saintbedeslytham.saintbedes.news");
startActivity(intent);
}
}
);
}
How, if anything, can I apply another method for the "saintbedeslytham.saintbedes.news"
Your problem here is that you cannot create two method with the same definition.
You have two:
protected void onCreate(Bundle savedInstanceState);
and two:
public void OnClickImageButtonListener();
You can't have 2 methods with the same definition for 2 simple reasons.Imagine 2 people with the same name, call for their name.
Who will answer?
Who are you calling?
Edit:
So you can:
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
prepareClicks();
}
private void prepareClicks() {
findViewById(R.id.imageButton).setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("saintbedeslytham.saintbedes.event");
startActivity(intent);
}
}
);
findViewById(R.id.imageButton2).setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("saintbedeslytham.saintbedes.news");
startActivity(intent);
}
}
);
}
}
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
prepareClicks();
}
private void prepareClicks() {
findViewById(R.id.imageButton).setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("saintbedeslytham.saintbedes.event");
startActivity(intent);
}
}
);
findViewById(R.id.imageButton2).setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("saintbedeslytham.saintbedes.news");
startActivity(intent);
}
}
);
}
}
Yup the method worked.
Thanks for the replies,
(Done by Gorcyn)

Categories

Resources