android 重新启动应用程序,通过单击应用程序图标打开Android应用程序时重新启动...

我是

Android开发世界的新手,我已经建立了一个简单的“Hello World”应用程序.首先,活动请求一个文本.当单击“Go”按钮时,应用程序将启动显示输入文本的第二个活动.

如果我单击HOME按钮,然后单击应用程序图标,该应用程序将再次启动第一个活动,但是如果我按住主屏幕按钮并单击“最近的应用程序”栏中的图标,它会恢复我离开的应用程序.

如何避免这种情况?

即使点击启动器图标,我也需要我的应用程序恢复.

MainActivity.java,

package com.example.myfirstandroidapp;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.Menu;

import android.view.View;

import android.widget.EditText;

public class MainActivity extends Activity {

public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main,menu);

return true;

}

/** Called when the user clicks the Send button */

public void sendMessage(View view){

// Do something in response to button

Intent intent = new Intent(this,DisplayMessageActivity.class);

EditText editText = (EditText) findViewById(R.id.txtName);

String message = editText.getText().toString();

intent.putExtra(EXTRA_MESSAGE,message);

startActivity(intent);

}

}

DisplayActivity.java,

package com.example.myfirstandroidapp;

import android.annotation.TargetApi;

import android.app.Activity;

import android.content.Intent;

import android.os.Build;

import android.os.Bundle;

import android.support.v4.app.NavUtils;

import android.view.Menu;

import android.view.MenuItem;

import android.widget.TextView;

public class DisplayMessageActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

// Get the message from the intent

Intent intent = getIntent();

String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

// Create the text view

TextView textView = new TextView(this);

textView.setTextSize(40);

textView.setText(message);

// Set the text view as the activity layout

setContentView(textView);

// Show the Up button in the action bar.

setupActionBar();

}

/**

* Set up the {@link android.app.ActionBar},if the API is available.

*/

@TargetApi(Build.VERSION_CODES.HONEYCOMB)

private void setupActionBar() {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

getActionBar().setDisplayHomeAsUpEnabled(true);

}

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.display_message,menu);

return true;

}

@Override

public void onDestroy(){

super.onDestroy();

}

@Override

public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {

case android.R.id.home:

// This ID represents the Home or Up button. In the case of this

// activity,the Up button is shown. Use NavUtils to allow users

// to navigate up one level in the application structure. For

// more details,see the Navigation pattern on Android Design:

//

// http://developer.android.com/design/patterns/navigation.html#up-vs-back

//

NavUtils.navigateUpFromSaMetask(this);

return true;

}

return super.onOptionsItemSelected(item);

}

}

activity_main.xml中,

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context=".MainActivity" >

android:id="@+id/txtName"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="70dp"

android:ems="10" >

android:id="@+id/btnGo"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignBottom="@+id/txtName"

android:layout_alignParentRight="true"

android:onClick="sendMessage"

android:text="Go!" />

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/txtName"

android:layout_alignParentTop="true"

android:layout_marginTop="18dp"

android:text="Please input your name:"

android:textAppearance="?android:attr/textAppearanceMedium" />

activity_display_message.xml,

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context=".DisplayMessageActivity" >

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/hello_world" />

AndroidManifest.xml中,

package="com.example.myfirstandroidapp"

android:versionCode="1"

android:versionName="1.0" >

android:minSdkVersion="9"

android:targetSdkVersion="10" />

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

android:name="com.example.myfirstandroidapp.MainActivity"

android:label="@string/app_name" >

android:name="com.example.myfirstandroidapp.DisplayMessageActivity"

android:label="@string/title_activity_display_message"

android:parentActivityName="com.example.myfirstandroidapp.MainActivity" >

android:name="android.support.PARENT_ACTIVITY"

android:value="com.example.myfirstandroidapp.MainActivity" />

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
应用程序无法正常启动(0xc0000007b)是一个常见的错误。它通常是由于系统缺少一些配置文件所导致的。一种解决办法是使用一个软件来帮助你安装这些文件。安装完之后可能需要重启电脑才能完美解决这个问题。 另外,你还可以尝试以下解决办法: 1. 更新操作系统:确保你的操作系统是最新版本,并且已经安装了所有的更新补丁。 2. 重新安装应用程序:尝试重新安装应用程序,以确保所有的文件和依赖项都正确安装。 3. 检查系统文件:运行系统文件检查工具,以确保系统文件没有损坏或丢失。 4. 安装所需的软件框架:某些应用程序可能需要特定的软件框架才能正常运行,例如.NET Framework或Visual C++ Redistributable包。确保这些框架已经安装并更新到最新版本。 5. 清理注册表:使用注册表清理工具来清理无效的注册表项,以解决可能由于注册表错误而引起的问题。 6. 检查病毒和恶意软件:运行安全扫描程序来检查系统是否感染了病毒或恶意软件,并及清除它们。 请注意,以上解决办法可能需要一些计算机知识和技能。如果你对这些操作不熟悉,建议寻求专业人士的帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [(完美解决)应用程序无法正常启动(0xc000007b),请单击确定关闭应用程序的解决方案](https://blog.csdn.net/weixin_36397141/article/details/105935900)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [DirectX Repair V3.9 (Enhanced Edition).rar](https://download.csdn.net/download/qq_17589751/12369361)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [【应用程序无法正常启动0xc000007b 请点击确定关闭应用程序】的错误如何解决?](https://blog.csdn.net/wzk4869/article/details/127822730)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值