我以为我已经弄清楚了,但是在对这个问题进行了一些调试之后:How to make notification uncancellable/unremovable我刚刚意识到我的 Activity 仍在以随机顺序进行 onCreated() 和 onDestroyed()。
我的 Activity list :
<activity
android:name="***.***.***.*****"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
我也尝试过 launchmodes singleTask、singleInstance。
我的通知 Intent 代码:
Intent intent = new Intent(context, MyClass.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
//intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//intent.setFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
//intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
如您所见,我已经尝试了所有可能相关的标志,但没有运气......
这会产生一些不需要的 Artifact ,例如重新启动我的 AlarmManager 并在每次单击通知时触发 alarmmanager 启动任务。我想避免这种情况。
有什么建议吗?
编辑:我知道有很多这样的问题,但这里提供的解决方案似乎都没有解决问题...:/
Edit2:根据要求,这是我的类(class):
package ***.***.***;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.PorterDuff;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MyClass extends FragmentActivity {
private static String userName;
String password;
private static Boolean LoggedIn = false;
private static Boolean RunningState = false;
private static Boolean OnlineState = false;
private static String LastReportTime;
private static Boolean isVisible = true;
private static Boolean firstStart = true;
private static TextView onlineTextView;
private static TextView reportTimeTextView;
private static TextView runningStatusTextView;
private static TextView userLoggedInTextView;
private static Context context;
public static final String PREFS_NAME = "Settings";
public static final String NOTIFICATION_RUNNING_OK = "Reporting Active";
public static final String NOTIFICATION_USER_STOPPED = "Reporting Stopped";
public static final String NOTIFICATION_NO_NETWORK = "No Network Connected";
public static final String NOTIFICATION_NO_CONNECTION = "No Connection To Server";
public static final int NOTIFICATION_ID = 10;
public static final int LOGIN_REQUEST_CODE = 1;
public static final int WAKEUP_LOGIN_REQUEST_CODE = 2;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Log.d("MyClass", "Main onCreate() Called");
loadVariables();
com.remobjects.sdk.TypeManager.setPackage("com.remobjects.sdk");
//if (firstStart)
//{
Log.d("MyClass", "Main onCreate() firstStart Called");
if (RunningState && checkConnection())
{
// After runLogin(), onResume() gets called here again immediately
setLoginCode(LOGIN_REQUEST_CODE);
runLogin();
}
else
init();
//}
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
}
@Override
public void onResume()
{
super.onResume();
Log.d("MyClass", "Main onResume() Called");
//firstStart gets set to false during login
if (!firstStart)
{
Log.d("MyClass", "Main onResume() !firstStart Called");
loadVariables();
setVisible(true);
updateUI();
}
}
@Override
protected void onPause()
{
super.onPause();
saveVariables();
setVisible(false);
}
@Override
protected void onStop()
{
super.onStop();
saveVariables();
setVisible(false);
}
@Override
public void onDestroy()
{
super.onDestroy();
//cancelNotification();
Log.e("MyClass", "onDestroy() called");
saveVariables();
setVisible(false);
//setFirstStart(true);
}
private void loadVariables()
{
SharedPreferences sharedPrefs = getSharedPreferences(PREFS_NAME, 0);
userName = sharedPrefs.getString("userName", "");
RunningState = sharedPrefs.getBoolean("RunningState", true);
LoggedIn = sharedPrefs.getBoolean("LoggedIn", false);
OnlineState = sharedPrefs.getBoolean("OnlineState", false);
LastReportTime = sharedPrefs.getString("LastReportTime", "");
context = this.getApplicationContext();
}
private static void saveVariables()
{
SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("userName", userName);
editor.putBoolean("RunningState", RunningState);
editor.putBoolean("LoggedIn", LoggedIn);
editor.putBoolean("OnlineState", OnlineState);
editor.putString("LastReportTime", LastReportTime);
editor.commit();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_my_class, menu);
return true;
}
private Boolean checkConnection()
{
Log.d("MyClass", "checkConnection()");
ConnectivityManager cnnxManager = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cnnxManager.getActiveNetworkInfo();
if (ni != null && ni.isAvailable() && ni.isConnected())
{
OnlineState = true;
return true;
}
OnlineState = false;
return false;
}
public void runLogin()
{
Intent intent = new Intent(context, LoginActivity.class);
startActivityForResult(intent, getLoginCode());
Log.d("MyClass", "runLogin()");
}
private void init()
{
Log.d("MyClass", "init()");
setContentView(R.layout.activity_field_agent);
onlineTextView = (TextView)findViewById(R.id.onlineStatusTextView);
reportTimeTextView = (TextView)findViewById(R.id.lastReportTimeTextView);
runningStatusTextView = (TextView)findViewById(R.id.runningStatusTextView);
userLoggedInTextView = (TextView)findViewById(R.id.userLoggedInTextView);
findViewById(R.id.button_online).getBackground().setColorFilter(0xFF00FF00, PorterDuff.Mode.MULTIPLY);
findViewById(R.id.button_highRisk).getBackground().setColorFilter(0xFFFFA500, PorterDuff.Mode.MULTIPLY);
findViewById(R.id.button_alarm).getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY);
setVisible(true);
updateUI();
if (RunningState)
{
setupAlarmManager(AlarmManager.INTERVAL_FIFTEEN_MINUTES);
// Here onResume() gets called again
updateNotificationText(NOTIFICATION_RUNNING_OK);
Button temp = (Button)findViewById(R.id.button_online);
temp.setCompoundDrawablesWithIntrinsicBounds(R.drawable.check_box, 0, R.drawable.check_box, 0);
}
else
{
//cancelAlarmManager();
updateNotificationText(NOTIFICATION_USER_STOPPED);
Button temp = (Button)findViewById(R.id.button_offline);
temp.setCompoundDrawablesWithIntrinsicBounds(R.drawable.check_box, 0, R.drawable.check_box, 0);
}
}
private void updateUI()
{
Log.d("MyClass", "updateUI()");
updateUserLoggedInStatus(userName);
updateOnlineStatus(OnlineState);
updateRunningStatus(RunningState);
updateReportTimeStatus(LastReportTime);
}
public void offDutyButton_click(View view)
{
cancelAlarmManager();
Button temp = (Button)findViewById(R.id.button_offline);
temp.setCompoundDrawablesWithIntrinsicBounds(R.drawable.check_box, 0, R.drawable.check_box, 0);
temp = (Button)findViewById(R.id.button_online);
temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
temp = (Button)findViewById(R.id.button_highRisk);
temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
temp = (Button)findViewById(R.id.button_alarm);
temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
public void onDutyButton_click(View view)
{
Button temp = (Button)findViewById(R.id.button_online);
temp.setCompoundDrawablesWithIntrinsicBounds(R.drawable.check_box, 0, R.drawable.check_box, 0);
temp = (Button)findViewById(R.id.button_offline);
temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
temp = (Button)findViewById(R.id.button_highRisk);
temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
temp = (Button)findViewById(R.id.button_alarm);
temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
//cancelAlarmManager();
setupAlarmManager(AlarmManager.INTERVAL_FIFTEEN_MINUTES);
}
public void highRiskButton_click(View view)
{
Button temp = (Button)findViewById(R.id.button_highRisk);
temp.setCompoundDrawablesWithIntrinsicBounds(R.drawable.check_box, 0, R.drawable.check_box, 0);
temp = (Button)findViewById(R.id.button_online);
temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
temp = (Button)findViewById(R.id.button_offline);
temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
temp = (Button)findViewById(R.id.button_alarm);
temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
public void alarmButton_click(View view)
{
Button temp = (Button)findViewById(R.id.button_alarm);
temp.setCompoundDrawablesWithIntrinsicBounds(R.drawable.check_box, 0, R.drawable.check_box, 0);
temp = (Button)findViewById(R.id.button_online);
temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
temp = (Button)findViewById(R.id.button_highRisk);
temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
temp = (Button)findViewById(R.id.button_offline);
temp.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
public static void setButtonIcon(int inId)
{
}
public static void showToast(String inString, Context context)
{
Toast.makeText(context, inString.toString(), Toast.LENGTH_SHORT).show();
}
public static void updateOnlineStatus(Boolean inStatus)
{
if (isVisible)
{
if (inStatus)
onlineTextView.setText("Online");
else
onlineTextView.setText("Offline");
}
}
public static void updateReportTimeStatus(String inString)
{
if (isVisible)
reportTimeTextView.setText(inString);
}
public static void updateRunningStatus(Boolean inStatus)
{
if (isVisible)
{
if (inStatus)
runningStatusTextView.setText("Reporting");
else
runningStatusTextView.setText("Not Reporting");
}
}
public static void updateUserLoggedInStatus(String inString)
{
if (isVisible)
userLoggedInTextView.setText(inString);
}
//
//
// Getters and Setters
//
//
public static void setLoggedIn(Boolean inBool)
{
LoggedIn = inBool;
}
public static Boolean getLoggedIn()
{
return LoggedIn;
}
public static void setRunningState(Boolean inBool)
{
RunningState = inBool;
}
public static Boolean getRunningState()
{
return RunningState;
}
public static void setVisible(Boolean inBool)
{
isVisible = inBool;
}
public static Boolean getVisible()
{
return isVisible;
}
public static void setUsername(String inString)
{
userName = inString;
}
public static String getUsername()
{
return userName;
}
public static void setLastReportTime(String inString)
{
LastReportTime = inString;
}
public static String getLastReportTime()
{
return LastReportTime;
}
public static Context getAppContext()
{
return MyClass.context;
}
public static void setLoginCode(int code)
{
SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putInt("LoginCode", code);
editor.commit();
}
public static int getLoginCode()
{
SharedPreferences sharedPrefs = context.getSharedPreferences(PREFS_NAME, 0);
return sharedPrefs.getInt("LoginCode", 1);
}
public static void setFirstStart(Boolean inBool)
{
firstStart = inBool;
}
public static Boolean getFirstStart()
{
return firstStart;
}
//
//
//
//
//
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode) {
case (LOGIN_REQUEST_CODE) : {
if (resultCode == Activity.RESULT_OK) {
LoggedIn = data.getBooleanExtra("LoggedIn", false);
userName = data.getStringExtra("Username");
init();
}
break;
}
case (WAKEUP_LOGIN_REQUEST_CODE) : {
if (resultCode == Activity.RESULT_OK) {
LoggedIn = data.getBooleanExtra("LoggedIn", false);
userName = data.getStringExtra("Username");
cancelAlarmManager();
setupAlarmManager(AlarmManager.INTERVAL_FIFTEEN_MINUTES);
}
break;
}
}
}
//
//
// AlarmManager
//
//
public static void setupAlarmManager(long interval)
{
AlarmManager alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent alarmIntent = new Intent(context, LaunchReceiver.class);
PendingIntent pendingAlarmIntent = PendingIntent.getBroadcast(context.getApplicationContext(), 0, alarmIntent, 0);
alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 0, interval, pendingAlarmIntent);
RunningState = true;
updateRunningStatus(RunningState);
updateNotificationText(NOTIFICATION_RUNNING_OK);
Log.d("MyClass", "AlarmManager Started");
}
public static void cancelAlarmManager()
{
Intent intent = new Intent(context.getApplicationContext(), LaunchReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
AlarmManager alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
alarmMgr.cancel(pendingIntent);
RunningState = false;
updateRunningStatus(RunningState);
updateNotificationText(NOTIFICATION_USER_STOPPED);
Log.d("MyClass", "AlarmManager Stopped");
Intent serviceIntent = new Intent(context, MonitorService.class);
context.stopService(serviceIntent);
Log.d("MyClass", "Stopping MonitorService");
}
//
//
// Notification
//
//
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void createNotification()
{
NotificationManager notificationManager = (NotificationManager)context.getSystemService(NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentTitle("blablabla")
.setContentText("Getting Status")
.setSmallIcon(R.drawable.ic_launcher)
.setOngoing(true)
.setAutoCancel(false);
Intent intent = new Intent(context, MyClass.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
//intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//intent.setFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
//intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MyClass.class);
stackBuilder.addNextIntent(intent);
PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
/*Notification noti = builder.build();
noti.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;*/
notificationManager.notify(NOTIFICATION_ID, builder.build());
}
public static void updateNotificationText(String inString)
{
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentText(inString)
.setContentTitle("blablabla")
.setSmallIcon(R.drawable.ic_launcher)
.setOngoing(true)
.setAutoCancel(false);
Intent intent = new Intent(context, MyClass.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MyClass.class);
stackBuilder.addNextIntent(intent);
PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
/*Notification noti = builder.build();
noti.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;*/
notificationManager.notify(NOTIFICATION_ID, builder.build());
}
public static void cancelNotification()
{
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(NOTIFICATION_ID);
}
}
正如评论中提到的,在启动 loginActivity 后,这里的 onResume() 会立即再次被调用。启动alarmManager后也一样。
此外,每次 alarmManager 滴答作响时,似乎都会将应用程序带到前台。有什么办法可以避免吗?
最佳答案
看起来问题是由通知代码中的这些行引起的(直接取自 Android 的通知指南:
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(FieldAgent.class);
stackBuilder.addNextIntent(intent);
PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
用像这样的常规挂起 Intent 替换它们解决了它:
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
一个完整的例子
Intent intent = new Intent(getApplicationContext(), myactivity.class);
PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext(), (int)System.currentTimeMillis(), intent, 0);
Notification myNotification = new Notification.Builder(getApplicationContext())
.setContentTitle("Title")
.setContentText("Some text....")
.setSmallIcon(R.drawable.myicon)
.setContentIntent(pIntent)
.setAutoCancel(true).build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, myNotification);
关于android - 如何使通知恢复而不是重新创建 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16898047/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta