
假设我有四个班级.每个班级都有一个按钮,可以从一个页面切换到另一个页面,工作正常.但是现在我试图通过点击最后一页的按钮关闭所有活动.我试过了它也只是关闭了最后一页.如何实现这个概念?
请找我的代码以供参考
Xit_demoActivity.java
public class Xit_demoActivity extends Activity {/** Called when the activity is first created. */button btn1; @OverrIDepublic voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.main); btn1 = (button)findVIEwByID(R.ID.button_1); btn1.setonClickListener(new VIEw.OnClickListener() { public voID onClick(VIEw v) { Intent myIntent = new Intent(v.getContext(), Class1.class); startActivity(myIntent); } });Class1.java
public class Class1 extends Activity {button btn1;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.main1); btn1 = (button)findVIEwByID(R.ID.button_2); btn1.setonClickListener(new VIEw.OnClickListener() { public voID onClick(VIEw v) { Intent myIntent = new Intent(v.getContext(), Class2.class); startActivity(myIntent); } });Class2.java
public class Class2 extends Activity {button btn1;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.main2); btn1 = (button)findVIEwByID(R.ID.button_3); btn1.setonClickListener(new VIEw.OnClickListener() { public voID onClick(VIEw v) { Intent myIntent = new Intent(v.getContext(), Class3.class); startActivity(myIntent); } });Class3.java
public class Class3 extends Activity {@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.main3); button next = (button) findVIEwByID(R.ID.button_4); next.setonClickListener(new VIEw.OnClickListener() { public voID onClick(VIEw v) { Intent intent = new Intent(); setResult(RESulT_OK, intent); finish(); } });的Manifest.xml
<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"package="com.and.roIDu.xit"androID:versionCode="1"androID:versionname="1.0" ><uses-sdk androID:minSdkVersion="8" androID:targetSdkVersion="8" /><application androID:icon="@drawable/ic_launcher" androID:label="@string/app_name" > <activity androID:name=".Xit_demoActivity" 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=".Class1"></activity> <activity androID:name=".Class1" androID:label="@string/app_name" > <intent-filter> <action androID:name="androID.intent.action.MAIN1" /> <category androID:name="androID.intent.category.LAUNCHER" /> </intent-filter> </activity><activity androID:name=".Class2"></activity> <activity androID:name=".Class2" androID:label="@string/app_name" > <intent-filter> <action androID:name="androID.intent.action.MAIN2" /> <category androID:name="androID.intent.category.LAUNCHER" /> </intent-filter> </activity><activity androID:name=".Class3"></activity> <activity androID:name=".Class3" androID:label="@string/app_name" > <intent-filter> <action androID:name="androID.intent.action.MAIN3" /> <category androID:name="androID.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>谢谢你的时间!..
解决方法:
试试吧.考虑你的Class3.java是你的最后一个Activitiy而且,在下面使用的按钮下面代码 –
Intent intent = new Intent(currentActivity.this, Xitactivity.class); // instead of Xitactivity use your first activityintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_top);intent.putExtra("EXIT", true);startActivity(intent);而且,在你的Xit_demoActivity的onCreate()中使用下面的代码 –
if (getIntent().getBooleanExtra("EXIT", false)) { finish();}希望这可以帮助您退出所有活动.
总结以上是内存溢出为你收集整理的无法关闭android eclipse上的所有活动全部内容,希望文章能够帮你解决无法关闭android eclipse上的所有活动所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)