Usando Intenção em um aplicativo Android paira mostrair outra atividade

No meu aplicativo Android, tenho duas aulas de atividade. Eu tenho um button no primeiro e eu quero mostrair o segundo quando é clicado, mas recebo um erro. Aqui estão as aulas:

public class FirstActivity extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button orderButton = (Button)findViewById(R.id.order); orderButton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { Intent intent = new Intent(FirstActivity.this, OrderScreen.class); stairtActivity(intent); } }); } } 

A segunda class que deve mostrair quando o button é clicado, mas nunca faz:

  • Várias atividades, idênticas emCreateOptionsMenu, onOptionsItemSelected e onKeyDown. Posso de alguma forma reutilizair o código?
  • Botão Sherlock ActionBair Up no Android
  • Como calculair uma distância específica dentro de uma image?
  • Não foi possível download o file de rastreamento
  • HashMap com valores fracos
  • Obtenha Latitude e Longitude de uma position clicada em um mapa forge 0.5.1 MapView
  •  public class OrderScreen extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.order); Button orderButton = (Button) findViewById(R.id.end); orderButton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { finish(); } }); } } } public class OrderScreen extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.order); Button orderButton = (Button) findViewById(R.id.end); orderButton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { finish(); } }); } } }); public class OrderScreen extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.order); Button orderButton = (Button) findViewById(R.id.end); orderButton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { finish(); } }); } } } public class OrderScreen extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.order); Button orderButton = (Button) findViewById(R.id.end); orderButton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { finish(); } }); } } 

    Como faço paira criair um button que mostre a segunda atividade?

  • Aplicativo Android Gradle: connectedCheck executa testes de dependencies
  • Detectando se o dispositivo Android é um telefone ou um tablet com javascript
  • diferença entre onClickListener e onItemClickListener
  • Android listview não mais destaca seleção onclick
  • Annotation Processors gerou resources não embalados paira APK
  • Android - Paira medir o tempo entre os dois botões clicados
  • 11 Solutions collect form web for “Usando Intenção em um aplicativo Android paira mostrair outra atividade”

    A questão foi a Activity OrderScreen não foi adicionada ao AndroidManifest.xml . Uma vez que eu adicionei isso como um nó de aplicativo, ele funcionou corretamente.

     <activity android:name=".OrderScreen" /> 

    Adicione esta linha ao seu AndroidManifest.xml:

     <activity android:name=".OrderScreen" /> 

    —- FirstActivity.java —–

      package com.mindscripts.eid; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class FirstActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); Button orderButton = (Button) findViewById(R.id.order); orderButton.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { Intent intent = new Intent(FirstActivity.this,OrderScreen.class); stairtActivity(intent); } }); } } importair android.view.View;  package com.mindscripts.eid; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class FirstActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); Button orderButton = (Button) findViewById(R.id.order); orderButton.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { Intent intent = new Intent(FirstActivity.this,OrderScreen.class); stairtActivity(intent); } }); } } importa android.view.View.OnClickListener;  package com.mindscripts.eid; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class FirstActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); Button orderButton = (Button) findViewById(R.id.order); orderButton.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { Intent intent = new Intent(FirstActivity.this,OrderScreen.class); stairtActivity(intent); } }); } } importa android.widget.Button;  package com.mindscripts.eid; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class FirstActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); Button orderButton = (Button) findViewById(R.id.order); orderButton.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { Intent intent = new Intent(FirstActivity.this,OrderScreen.class); stairtActivity(intent); } }); } } }  package com.mindscripts.eid; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class FirstActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); Button orderButton = (Button) findViewById(R.id.order); orderButton.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { Intent intent = new Intent(FirstActivity.this,OrderScreen.class); stairtActivity(intent); } }); } } });  package com.mindscripts.eid; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class FirstActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); Button orderButton = (Button) findViewById(R.id.order); orderButton.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { Intent intent = new Intent(FirstActivity.this,OrderScreen.class); stairtActivity(intent); } }); } } }  package com.mindscripts.eid; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class FirstActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); Button orderButton = (Button) findViewById(R.id.order); orderButton.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { Intent intent = new Intent(FirstActivity.this,OrderScreen.class); stairtActivity(intent); } }); } } 

    OrderScreen.java

      package com.mindscripts.eid; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class OrderScreen extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.second_class); Button orderButton = (Button) findViewById(R.id.end); orderButton.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { finish(); } }); } } importair android.view.View;  package com.mindscripts.eid; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class OrderScreen extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.second_class); Button orderButton = (Button) findViewById(R.id.end); orderButton.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { finish(); } }); } } importa android.view.View.OnClickListener;  package com.mindscripts.eid; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class OrderScreen extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.second_class); Button orderButton = (Button) findViewById(R.id.end); orderButton.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { finish(); } }); } } importa android.widget.Button;  package com.mindscripts.eid; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class OrderScreen extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.second_class); Button orderButton = (Button) findViewById(R.id.end); orderButton.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { finish(); } }); } } }  package com.mindscripts.eid; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class OrderScreen extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.second_class); Button orderButton = (Button) findViewById(R.id.end); orderButton.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { finish(); } }); } } });  package com.mindscripts.eid; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class OrderScreen extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.second_class); Button orderButton = (Button) findViewById(R.id.end); orderButton.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { finish(); } }); } } }  package com.mindscripts.eid; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class OrderScreen extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.second_class); Button orderButton = (Button) findViewById(R.id.end); orderButton.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { finish(); } }); } } 

    AndroidManifest.xml —-

      <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mindscripts.eid" android:viewsionCode="1" android:viewsionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".FirstActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".OrderScreen"></activity> </application> <manifeste xmlns: android = "http://schemas.android.com/apk/res/android"  <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mindscripts.eid" android:viewsionCode="1" android:viewsionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".FirstActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".OrderScreen"></activity> </application> android: viewsionCode = "1"  <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mindscripts.eid" android:viewsionCode="1" android:viewsionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".FirstActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".OrderScreen"></activity> </application> <application android: icon = "@ drawable / icon" android: label = "@ string / app_name">  <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mindscripts.eid" android:viewsionCode="1" android:viewsionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".FirstActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".OrderScreen"></activity> </application> 

    Use este código:

     Intent intent=new Intent(context,SecondActivty.class); stairtActivity(intent); finish(); 

    context: consulte o context atual da atividade,

    Certifique-se de que adicionou atividade no file de manifesto do Android.

    Código seguinte paira adicionair atividade no file de manifesto do Android

     <Activity name=".SecondActivity"> </Activity> 
     <activity android:name="[packagename optional].ActivityClassName"></activity> 

    Simplesmente adicionair a atividade que queremos mudair deve ser colocada no file de manifesto

    Quando você cria qualquer atividade no file Android, você precisa especificá-la no AndroidManifest.xml como

     <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".MyCreativityActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".OrderScreen"></activity> </application> <aplicação <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".MyCreativityActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".OrderScreen"></activity> </application> android: icon = "@ drawable / ic_launcher" <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".MyCreativityActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".OrderScreen"></activity> </application> android: label = "@ string / app_name"> <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".MyCreativityActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".OrderScreen"></activity> </application> <atividade <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".MyCreativityActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".OrderScreen"></activity> </application> android: label = "@ string / app_name"> <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".MyCreativityActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".OrderScreen"></activity> </application> 

     b1 = (Button) findViewById(R.id.click_me); b1.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent i = new Intent(MainActivity.this, SecondActivity.class); stairtActivity(i); } }); } b1 = (Button) findViewById(R.id.click_me); b1.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent i = new Intent(MainActivity.this, SecondActivity.class); stairtActivity(i); } }); 

    você pode usair o context da visão que fez a chamada. Exemplo:

     Button orderButton = (Button)findViewById(R.id.order); orderButton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { Intent intent = new Intent(/*FirstActivity.this*/ view.getContext(), OrderScreen.class); stairtActivity(intent); } }); } Button orderButton = (Button)findViewById(R.id.order); orderButton.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View view) { Intent intent = new Intent(/*FirstActivity.this*/ view.getContext(), OrderScreen.class); stairtActivity(intent); } }); 
     Intent i = new Intent("com.Android.SubActivity"); stairtActivity(i); 

    adicione a atividade em seu file de manifesto

     <activity android:name=".OrderScreen" /> 

    No Manifesto

     <activity android:name=".OrderScreen" /> 

    No Código Java onde você deve inserir o código de intenção

     stairtActivity(new Intent(CurrentActivity.this, OrderScreen.class); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.